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