| 274 | #define MAXLASTD cast_int(LUA_MAXINTEGER % 10) |
| 275 | |
| 276 | static const char *l_str2int (const char *s, lua_Integer *result) { |
| 277 | lua_Unsigned a = 0; |
| 278 | int empty = 1; |
| 279 | int neg; |
| 280 | while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ |
| 281 | neg = isneg(&s); |
| 282 | if (s[0] == '0' && |
| 283 | (s[1] == 'x' || s[1] == 'X')) { /* hex? */ |
| 284 | s += 2; /* skip '0x' */ |
| 285 | for (; lisxdigit(cast_uchar(*s)); s++) { |
| 286 | a = a * 16 + luaO_hexavalue(*s); |
| 287 | empty = 0; |
| 288 | } |
| 289 | } |
| 290 | else { /* decimal */ |
| 291 | for (; lisdigit(cast_uchar(*s)); s++) { |
| 292 | int d = *s - '0'; |
| 293 | if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ |
| 294 | return NULL; /* do not accept it (as integer) */ |
| 295 | a = a * 10 + d; |
| 296 | empty = 0; |
| 297 | } |
| 298 | } |
| 299 | while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */ |
| 300 | if (empty || *s != '\0') return NULL; /* something wrong in the numeral */ |
| 301 | else { |
| 302 | *result = l_castU2S((neg) ? 0u - a : a); |
| 303 | return s; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | |
| 308 | size_t luaO_str2num (const char *s, TValue *o) { |
no test coverage detected