CID 22500 Argument cannot be negative

This commit is contained in:
Enno Rehling 2015-11-04 12:29:51 +01:00
parent 5887e8e48f
commit 8bc44d82ed
1 changed files with 20 additions and 16 deletions

View File

@ -833,25 +833,29 @@ static void json_include(cJSON *json) {
F = fopen(child->valuestring, "rt");
}
if (F) {
cJSON *config;
char *data;
size_t sz;
long pos;
fseek(F, 0, SEEK_END);
sz = ftell(F);
pos = ftell(F);
rewind(F);
data = malloc(sz+1);
sz = fread(data, 1, sz, F);
data[sz] = 0;
if (pos > 0) {
cJSON *config;
char *data;
size_t sz;
data = malloc(pos + 1);
sz = fread(data, 1, (size_t)pos, F);
data[sz] = 0;
config = cJSON_Parse(data);
free(data);
if (config) {
json_config(config);
cJSON_Delete(config);
}
else {
log_error("invalid JSON, could not parse %s", child->valuestring);
}
}
fclose(F);
config = cJSON_Parse(data);
free(data);
if (config) {
json_config(config);
cJSON_Delete(config);
}
else {
log_error("invalid JSON, could not parse %s", child->valuestring);
}
}
}
}