|
|
@ -1,6 +1,6 @@
|
|
|
|
#pragma once
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
@ -156,14 +156,18 @@ parse_uint32_t(jsmntok_t tok, const char *json_buf, const char *key, uint32_t *r
|
|
|
|
static inline int
|
|
|
|
static inline int
|
|
|
|
parse_uint64_t(jsmntok_t tok, const char *json_buf, const char *key, uint64_t *ret)
|
|
|
|
parse_uint64_t(jsmntok_t tok, const char *json_buf, const char *key, uint64_t *ret)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *end = NULL;
|
|
|
|
if (json_buf[tok.start] == '-') {
|
|
|
|
intmax_t temp = strtoimax(&json_buf[tok.start], &end, 10);
|
|
|
|
fprintf(stderr, "Unable to parse uint64_t for key %s, had negative number\n", key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (end != &json_buf[tok.end] || temp < 0 || temp > UINT64_MAX) {
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
char *end = NULL;
|
|
|
|
|
|
|
|
uintmax_t temp = strtoumax(&json_buf[tok.start], &end, 10);
|
|
|
|
|
|
|
|
if (end != &json_buf[tok.end] || (temp == UINT64_MAX && errno == ERANGE)) {
|
|
|
|
fprintf(stderr, "Unable to parse uint64_t for key %s\n", key);
|
|
|
|
fprintf(stderr, "Unable to parse uint64_t for key %s\n", key);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*ret = (uint64_t)temp;
|
|
|
|
*ret = temp;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|