From f33018188bf5bdf6f6b8af0d646e3f8c519d9d71 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Thu, 23 Mar 2017 12:13:44 -0700 Subject: Added support for empty string in config.json & other cleanup. --- redist/json_helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'redist/json_helpers.c') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 0267932..3b5cc0d 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -117,7 +117,8 @@ char* load_file_to_mem(const char* path) { fseek( f, 0, SEEK_END ); int len = ftell( f ); fseek( f, 0, SEEK_SET ); - char * JSON_STRING = malloc( len ); + char * JSON_STRING = malloc( len + 1); + memset(JSON_STRING,0,len+1); fread( JSON_STRING, len, 1, f ); fclose( f ); return JSON_STRING; -- cgit v1.2.3 From 4dc1d72785c660c206f8def9d8c8aa32289c2709 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Fri, 24 Mar 2017 15:19:59 -0700 Subject: More cleanup & finishing genericization of calibrator --- redist/json_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'redist/json_helpers.c') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 3b5cc0d..29d48bd 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -174,7 +174,7 @@ void json_load_file(const char* path) { int16_t children = -1; - for (i=0; i<(int)items; i+=2) + for (i=0; i<(unsigned int)items; i+=2) { //increment i on each successful tag + values combination, not individual tokens jsmntok_t* tag_t = tokens+i; -- cgit v1.2.3 From 57feef80252b28362b3adbee1e587467b3f329b0 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sat, 29 Apr 2017 17:10:40 -0400 Subject: cleanup warnings --- redist/json_helpers.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'redist/json_helpers.c') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 29d48bd..c52301d 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -50,44 +50,46 @@ void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { uint8_t i = 0; char * str1 = NULL; char * str2 = NULL; - asprintf(&str1,"\"%s\":[", tag); + if( asprintf(&str1,"\"%s\":[", tag) < 0 ) goto giveup; for (i=0;i Date: Sat, 6 May 2017 22:05:32 -0400 Subject: add function to parse array of floats from json --- redist/json_helpers.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'redist/json_helpers.c') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index c52301d..af7ddda 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -216,3 +216,32 @@ 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;iend; + char* s = str+token->start; + + #ifdef USE_DOUBLE + (*f)[i] = strtod(s, &end); + #else + (*f)[i] = strtof(s, &end); + #endif + + if (s == end) { + free(*f); + *f=NULL; + return 0; //not a float + } + token++; + } + + + return count; +} \ No newline at end of file -- cgit v1.2.3