refactor: JSON_TOKENS_CAPACITY

master
Sean McBride 3 years ago
parent 8f2f18722d
commit e6b4119652

@ -14,8 +14,7 @@
#include "module.h" #include "module.h"
#include "module_config.h" #include "module_config.h"
static const int JSON_MAX_ELEMENT_COUNT = 16; #define JSON_TOKENS_CAPACITY 1024
static const int JSON_MAX_ELEMENT_SIZE = 1024;
static inline char * static inline char *
jsmn_type(jsmntype_t type) jsmn_type(jsmntype_t type)
@ -145,7 +144,7 @@ parse_json(const char *json_buf, ssize_t json_buf_size, struct module_config **m
assert(json_buf_size > 0); assert(json_buf_size > 0);
assert(module_config_vec != NULL); assert(module_config_vec != NULL);
jsmntok_t tokens[JSON_MAX_ELEMENT_SIZE * JSON_MAX_ELEMENT_COUNT]; jsmntok_t tokens[JSON_TOKENS_CAPACITY];
int module_config_vec_len = 0; int module_config_vec_len = 0;
@ -154,8 +153,7 @@ parse_json(const char *json_buf, ssize_t json_buf_size, struct module_config **m
jsmn_init(&module_parser); jsmn_init(&module_parser);
/* Use Jasmine to parse the JSON */ /* Use Jasmine to parse the JSON */
int total_tokens = jsmn_parse(&module_parser, json_buf, json_buf_size, tokens, int total_tokens = jsmn_parse(&module_parser, json_buf, json_buf_size, tokens, JSON_TOKENS_CAPACITY);
sizeof(tokens) / sizeof(tokens[0]));
if (total_tokens < 0) { if (total_tokens < 0) {
if (total_tokens == JSMN_ERROR_INVAL) { if (total_tokens == JSMN_ERROR_INVAL) {
fprintf(stderr, "Error parsing %s: bad token, JSON string is corrupted\n", json_buf); fprintf(stderr, "Error parsing %s: bad token, JSON string is corrupted\n", json_buf);

Loading…
Cancel
Save