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

View file

@ -833,25 +833,29 @@ static void json_include(cJSON *json) {
F = fopen(child->valuestring, "rt"); F = fopen(child->valuestring, "rt");
} }
if (F) { if (F) {
cJSON *config; long pos;
char *data;
size_t sz;
fseek(F, 0, SEEK_END); fseek(F, 0, SEEK_END);
sz = ftell(F); pos = ftell(F);
rewind(F); rewind(F);
data = malloc(sz+1); if (pos > 0) {
sz = fread(data, 1, sz, F); cJSON *config;
data[sz] = 0; 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); 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);
}
} }
} }
} }