mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-05 17:29:43 +08:00
Handle sign when converting integer strings to numbers.
This commit is contained in:
11
jsvalue.c
11
jsvalue.c
@@ -205,8 +205,15 @@ double js_stringtofloat(const char *s, char **ep)
|
||||
}
|
||||
if (isflt)
|
||||
n = js_strtod(s, &end);
|
||||
else
|
||||
n = js_strtol(s, &end, 10);
|
||||
else {
|
||||
/* js_strtol doesn't parse the sign */
|
||||
if (*s == '-')
|
||||
n = -js_strtol(s+1, &end, 10);
|
||||
else if (*s == '+')
|
||||
n = js_strtol(s+1, &end, 10);
|
||||
else
|
||||
n = js_strtol(s, &end, 10);
|
||||
}
|
||||
if (end == e) {
|
||||
*ep = (char*)e;
|
||||
return n;
|
||||
|
||||
Reference in New Issue
Block a user