diff options
Diffstat (limited to 'redist/json_helpers.c')
-rw-r--r-- | redist/json_helpers.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 0741c84..fa76c16 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -213,27 +213,18 @@ void json_load_file(const char* path) { free(JSON_STRING); } -int parse_float_array(char* str, jsmntok_t* token, FLT** f, uint8_t count) { - uint16_t i = 0; - - if (count==0) return 0; - - if (*f!=NULL) free(*f); - *f = malloc(sizeof(FLT) * count); - - for(i=0;i<count;++i) { +int parse_float_array_in_place(char *str, jsmntok_t *token, FLT *f, uint8_t count) { + for (int i = 0; i < count; ++i) { char* end = str + token->end; char* s = str+token->start; #ifdef USE_DOUBLE - (*f)[i] = strtod(s, &end); + f[i] = strtod(s, &end); #else - (*f)[i] = strtof(s, &end); + f[i] = strtof(s, &end); #endif if (s == end) { - free(*f); - *f=NULL; return 0; //not a float } token++; @@ -242,3 +233,21 @@ int parse_float_array(char* str, jsmntok_t* token, FLT** f, uint8_t count) { return count; } +int parse_float_array(char *str, jsmntok_t *token, FLT **f, uint8_t count) { + uint16_t i = 0; + + if (count == 0) + return 0; + + if (*f != NULL) + free(*f); + *f = malloc(sizeof(FLT) * count); + + int rtn = parse_float_array_in_place(str, token, *f, count); + if (rtn == 0) { + free(*f); + *f = 0; + } + + return count; +} |