| 60 | |
| 61 | |
| 62 | bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num) |
| 63 | { |
| 64 | char *end; |
| 65 | unsigned long long l; |
| 66 | |
| 67 | errno = 0; |
| 68 | /* Decimal only, as for json_to_s64 below; and strtoull would |
| 69 | * happily negate a leading '-', which is not an unsigned number. */ |
| 70 | if (tok->start == tok->end || buffer[tok->start] == '-') |
| 71 | return false; |
| 72 | l = strtoull(buffer + tok->start, &end, 10); |
| 73 | if (end != buffer + tok->end) |
| 74 | return false; |
| 75 | |
| 76 | BUILD_ASSERT(sizeof(l) >= sizeof(*num)); |
| 77 | *num = l; |
| 78 | |
| 79 | /* Check for overflow */ |
| 80 | if (l == ULLONG_MAX && errno == ERANGE) |
| 81 | return false; |
| 82 | |
| 83 | if (*num != l) |
| 84 | return false; |
| 85 | |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num) |
| 90 | { |