Skip to content

Some natives return wrong length for truncated string #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
NexiusTailer opened this issue Apr 20, 2025 · 1 comment
Open

Some natives return wrong length for truncated string #1080

NexiusTailer opened this issue Apr 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@NexiusTailer
Copy link
Contributor

NexiusTailer commented Apr 20, 2025

Describe the bug
If the current behavior is not an intended thing, all the following natives:

  • SHA256_PassHash
  • GetPlayerIp
  • GetPlayerVersion
  • GetPlayerName
  • GetSVarString
  • GetPVarString
  • gpci

should return the final actual length of a string if it was truncated.

SHA256_PassHash

To Reproduce

new str[32]; // less than needed for hash
new ret = SHA256_PassHash("test", "78sdjs86d2h", str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 32, str 'CD16A1C8BF5792B48142FF6B67C9CB5B'

Current behavior

ret 65, str 'CD16A1C8BF5792B48142FF6B67C9CB5'
GetPlayerIp

To Reproduce

new str[3]; // less than needed for ip address
new ret = GetPlayerIp(playerid, str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 3, str '127'

Current behavior

ret 9, str '12'
GetPlayerVersion

To Reproduce

new str[3]; // less than needed for version
new ret = GetPlayerVersion(playerid, str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 3, str '0.3'

Current behavior

ret 5, str '0.'
GetPlayerName

To Reproduce

new str[3]; // less than needed for name
new ret = GetPlayerName(playerid, str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 3, str 'Nex'

Current behavior

ret 6, str 'Ne'
GetSVarString

To Reproduce

new str[3]; // less than needed for string
SetSVarString("test", "abracadabra");
new ret = GetSVarString("test", str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 3, str 'abr'

Current behavior

ret 11, str 'ab'
GetPVarString

To Reproduce

new str[3]; // less than needed for string
SetPVarString(playerid, "test", "abracadabra");
new ret = GetPVarString(playerid, "test", str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 3, str 'abr'

Current behavior

ret 11, str 'ab'
gpci

To Reproduce

new str[3]; // less than needed for serial
new ret = gpci(playerid, str, sizeof str);
printf("ret %d, str '%s'", ret, str);

Expected behavior

ret 3, str 'C44'

Current behavior

ret 40, str 'C4'
@NexiusTailer NexiusTailer added the bug Something isn't working label Apr 20, 2025
@NexiusTailer NexiusTailer changed the title SHA256_PassHash returns wrong length for truncated string Some natives return wrong length for truncated string Apr 20, 2025
@Vince0789
Copy link

To be honest, I think a warning should be printed if the output string is truncated; I can't think of a scenario where it would make sense to purposely truncate the string. Certainly not for any of the functions listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants