| 297 | #define MAXLASTD cast_int(LUA_MAXINTEGER % 10) |
| 298 | |
| 299 | static const char *l_str2int (const char *s, lua_Integer *result) { |
| 300 | lua_Unsigned a = 0; |
| 301 | int empty = 1; |
| 302 | int neg; |
| 303 | while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ |
| 304 | neg = isneg(&s); |
| 305 | if (s[0] == '0' && |
| 306 | (s[1] == 'x' || s[1] == 'X')) { /* hex? */ |
| 307 | s += 2; /* skip '0x' */ |
| 308 | for (; lisxdigit(cast_uchar(*s)); s++) { |
| 309 | a = a * 16 + luaO_hexavalue(*s); |
| 310 | empty = 0; |
| 311 | } |
| 312 | } |
| 313 | else { /* decimal */ |
| 314 | for (; lisdigit(cast_uchar(*s)); s++) { |
| 315 | int d = *s - '0'; |
| 316 | if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ |
| 317 | return NULL; /* do not accept it (as integer) */ |
| 318 | a = a * 10 + d; |
| 319 | empty = 0; |
| 320 | } |
| 321 | } |
| 322 | while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */ |
| 323 | if (empty || *s != '\0') return NULL; /* something wrong in the numeral */ |
| 324 | else { |
| 325 | *result = l_castU2S((neg) ? 0u - a : a); |
| 326 | return s; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | |
| 331 | size_t luaO_str2num (const char *s, TValue *o) { |
no test coverage detected