mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 01:41:37 +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)
|
if (isflt)
|
||||||
n = js_strtod(s, &end);
|
n = js_strtod(s, &end);
|
||||||
else
|
else {
|
||||||
n = js_strtol(s, &end, 10);
|
/* 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) {
|
if (end == e) {
|
||||||
*ep = (char*)e;
|
*ep = (char*)e;
|
||||||
return n;
|
return n;
|
||||||
|
|||||||
Reference in New Issue
Block a user