open.mp icon indicating copy to clipboard operation
open.mp copied to clipboard

Some natives return wrong length for truncated string

Open NexiusTailer opened this issue 6 months ago • 0 comments

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 avatar Apr 20 '25 13:04 NexiusTailer