Fix setAmxString cutting off the last character of strings#385
Merged
Conversation
Contributor
Author
|
tested on a live 5.29 server, same version so the only diff is the patch. vanilla: patched: [A] is the check: tight buffer + charsmax, vanilla drops the last char, patched keeps it. sizeof works in both. test plugin: #include <amxmodx>
#include <reapi>
public plugin_init()
{
register_plugin("setAmxString test", "1.0", "test")
register_srvcmd("test_setamxstr", "cmd_test")
}
public cmd_test()
{
new ent = rg_create_entity("info_target")
if (!is_entity(ent)) return PLUGIN_HANDLED;
new tight[12] // "info_target" = 11 chars, charsmax = 11
get_entvar(ent, var_classname, tight, charsmax(tight))
server_print("[A] tight='%s' -> %s", tight, equal(tight, "info_target") ? "PASS" : "FAIL")
new tight2[12]
get_entvar(ent, var_classname, tight2, sizeof(tight2))
server_print("[B] sizeof='%s' -> %s", tight2, equal(tight2, "info_target") ? "correct" : "differs")
rg_remove_entity(ent)
return PLUGIN_HANDLED;
} |
metita
force-pushed
the
harden-setamxstring-bounds
branch
from
July 20, 2026 05:57
3bfdb6f to
8be9578
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #383.
3c08fde changed setAmxString to treat max as the full buffer size and reserve a cell for the null terminator. But plugins pass charsmax(), which already excludes the null, so every native that returns a string (get_entvar, get_member, ...) ended up dropping the last character.
This reverts the length handling back to the original charsmax behavior.