aboutsummaryrefslogtreecommitdiff
path: root/redist
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2017-04-29 17:10:40 -0400
committercnlohr <lohr85@gmail.com>2017-04-29 17:10:40 -0400
commit57feef80252b28362b3adbee1e587467b3f329b0 (patch)
tree36ba8d75d6f5960fac4ee15a63797b5254af6e0e /redist
parent5e934529f953794f7d8a070766fd56e02eeb8b05 (diff)
downloadlibsurvive-57feef80252b28362b3adbee1e587467b3f329b0.tar.gz
libsurvive-57feef80252b28362b3adbee1e587467b3f329b0.tar.bz2
cleanup warnings
Diffstat (limited to 'redist')
-rw-r--r--redist/json_helpers.c28
1 files changed, 15 insertions, 13 deletions
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<count;++i) {
if ( (i+1) < count) {
- asprintf(&str2, "%s\"%f\"", str1,v[i]);
+ if( asprintf(&str2, "%s\"%f\"", str1,v[i]) < 0 ) goto giveup;
} else {
- asprintf(&str2, "%s\"%f\",", str1,v[i]);
+ if( asprintf(&str2, "%s\"%f\",", str1,v[i]) < 0 ) goto giveup;
}
free(str1);
str1=str2;
str2=NULL;
}
- asprintf(&str2, "%s]", str1);
+ if( asprintf(&str2, "%s]", str1) < 0 ) goto giveup;
fputs(str2,f);
- free(str1);
- free(str2);
+giveup:
+ if( str1 ) free(str1);
+ if( str2 ) free(str2);
}
void json_write_double_array(FILE* f, const char* tag, double* 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<count;++i) {
if (i<(count-1)) {
- asprintf(&str2, "%s\"%f\",", str1,v[i]);
+ if( asprintf(&str2, "%s\"%f\",", str1,v[i]) < 0 ) goto giveup;
} else {
- asprintf(&str2, "%s\"%f\"", str1,v[i]);
+ if( asprintf(&str2, "%s\"%f\"", str1,v[i]) < 0 ) goto giveup;
}
free(str1);
str1=str2;
str2=NULL;
}
- asprintf(&str2, "%s]", str1);
+ if( asprintf(&str2, "%s]", str1) < 0 ) goto giveup;
fputs(str2,f);
- free(str1);
- free(str2);
+giveup:
+ if( str1 ) free(str1);
+ if( str2 ) free(str2);
}
void json_write_uint32(FILE* f, const char* tag, uint32_t v) {
@@ -119,7 +121,7 @@ char* load_file_to_mem(const char* path) {
fseek( f, 0, SEEK_SET );
char * JSON_STRING = malloc( len + 1);
memset(JSON_STRING,0,len+1);
- fread( JSON_STRING, len, 1, f );
+ int i = fread( JSON_STRING, len, 1, f ); i = i; //Ignore return value.
fclose( f );
return JSON_STRING;
}