File tree 1 file changed +18
-9
lines changed
1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -287,18 +287,27 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
287
287
} else {
288
288
const char * p = strdata (lj_lib_checkstr (L , 1 ));
289
289
char * ep ;
290
+ unsigned int neg = 0 ;
290
291
unsigned long ul ;
291
292
if (base < 2 || base > 36 )
292
293
lj_err_arg (L , 2 , LJ_ERR_BASERNG );
293
- ul = strtoul (p , & ep , base );
294
- if (p != ep ) {
295
- while (lj_char_isspace ((unsigned char )(* ep ))) ep ++ ;
296
- if (* ep == '\0' ) {
297
- if (LJ_DUALNUM && LJ_LIKELY (ul < 0x80000000u ))
298
- setintV (L -> base - 1 - LJ_FR2 , (int32_t )ul );
299
- else
300
- setnumV (L -> base - 1 - LJ_FR2 , (lua_Number )ul );
301
- return FFH_RES (1 );
294
+ while (lj_char_isspace ((unsigned char )(* p ))) p ++ ;
295
+ if (* p == '-' ) { p ++ ; neg = 1 ; } else if (* p == '+' ) { p ++ ; }
296
+ if (lj_char_isalnum ((unsigned char )(* p ))) {
297
+ ul = strtoul (p , & ep , base );
298
+ if (p != ep ) {
299
+ while (lj_char_isspace ((unsigned char )(* ep ))) ep ++ ;
300
+ if (* ep == '\0' ) {
301
+ if (LJ_DUALNUM && LJ_LIKELY (ul < 0x80000000u + neg )) {
302
+ if (neg ) ul = - ul ;
303
+ setintV (L -> base - 1 - LJ_FR2 , (int32_t )ul );
304
+ } else {
305
+ lua_Number n = (lua_Number )ul ;
306
+ if (neg ) n = - n ;
307
+ setnumV (L -> base - 1 - LJ_FR2 , n );
308
+ }
309
+ return FFH_RES (1 );
310
+ }
302
311
}
303
312
}
304
313
}
You can’t perform that action at this time.
0 commit comments