Bugzilla – Bug 3233
is_str_num doesn't detect negative or signed integers
Last modified: 2014-02-08 23:52:15 PST
is_str_num should return true on negative numbers, and ones with a preceding '+'. Proposed fix: <code> stock bool:is_str_num(const sString[]) { new i = 0,bool:signed; if(sString[0] == '-' || sString[0] == '+') { signed = true ++i } while (sString[i] && isdigit(sString[i])) ++i; return sString[i] == 0 && (signed ? i != 0 : i > 1); } </code>
Ups,little mistake: return sString[i] == 0 && (signed ? i != 0 : i > 1); should be: return sString[i] == 0 && (!signed ? i != 0 : i > 1);
Created attachment 1382 [details] [review] proposed fix
Comment on attachment 1382 [details] [review] proposed fix "123lol" would previously return false, now it returns true the same goes for any combination of letters after a valid number that atoi() would recognize.
In that vein I think fixing this at all might be a compatibility risk, i.e.: if (!is_str_num(x)) return y = v[strtonum(x)] i'm willing to either let this not block or to add a strtol() native
Created attachment 3396 [details] Proposed patch strtol() implementation. Tested.
Pushed changeset: http://hg.alliedmods.net/amxmodx-central/rev/8f3605ea03d5 Changelog: Add strtol native (bug 3233, r=joropito)
Commit pushed to master at https://github.com/alliedmodders/amxmodx https://github.com/alliedmodders/amxmodx/commit/873fb6924f17d86887295a2eba32375816aeb956 Add strtol native (bug 3233, r=joropito) Former-commit-id: 9508f9f86db99e93de1819f585c741396d8e4c30