Bug 3233 - is_str_num doesn't detect negative or signed integers
is_str_num doesn't detect negative or signed integers
Status: RESOLVED FIXED
Product: AMX Mod X
Classification: Unclassified
Component: Core
trunk
PC All
: P4 normal
Assigned To: David Anderson [:dvander]
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-08-11 12:49 PDT by danielkza
Modified: 2014-02-08 23:52 PST (History)
3 users (show)

See Also:
dvander: blocking‑1.8.2-


Attachments
proposed fix (1.53 KB, patch)
2009-01-16 08:43 PST, David Anderson [:dvander]
sdudenhoeffer: review-
Details | Diff | Splinter Review
Proposed patch (4.18 KB, text/plain)
2013-06-27 06:24 PDT, Vincent Herbet [:Arkshine]
hv.contact: review+
joropito: feedback+
Details

Description danielkza 2008-08-11 12:49:23 PDT
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>
Comment 1 danielkza 2008-08-11 12:55:49 PDT
Ups,little mistake:
return sString[i] == 0 && (signed ? i != 0 : i > 1);

should be:
return sString[i] == 0 && (!signed ? i != 0 : i > 1);
Comment 2 David Anderson [:dvander] 2009-01-16 08:43:23 PST
Created attachment 1382 [details] [review]
proposed fix
Comment 3 sawce 2009-01-17 04:31:51 PST
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.
Comment 4 David Anderson [:dvander] 2009-02-05 20:41:44 PST
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
Comment 5 Vincent Herbet [:Arkshine] 2013-06-27 06:24:18 PDT
Created attachment 3396 [details]
Proposed patch

strtol() implementation. Tested.
Comment 6 Vincent Herbet [:Arkshine] 2013-07-04 11:45:30 PDT
Pushed changeset: http://hg.alliedmods.net/amxmodx-central/rev/8f3605ea03d5
Changelog:
	Add strtol native (bug 3233, r=joropito)
Comment 7 AM Bugzilla Bot 2014-02-08 23:52:15 PST
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

Note You need to log in before you can comment on or make changes to this bug.