Checking that fread *actually* succeeds, fix the warning bellow when compiling with -O1, -O2 or -O3.

"warning: ignoring return value of 'fread', declared with attribute warn_unused_result"
pull/8/head
Sylvain Miermont 11 years ago
parent a024f1197c
commit cbb51719cf
  1. 2
      parson.c

@ -500,7 +500,7 @@ JSON_Value * json_parse_file(const char *filename) {
rewind(fp); rewind(fp);
file_contents = (char*)parson_malloc(sizeof(char) * (file_size + 1)); file_contents = (char*)parson_malloc(sizeof(char) * (file_size + 1));
if (!file_contents) { fclose(fp); return NULL; } if (!file_contents) { fclose(fp); return NULL; }
fread(file_contents, file_size, 1, fp); if (fread(file_contents, file_size, 1, fp) < 1) { fclose(fp); return NULL; }
fclose(fp); fclose(fp);
file_contents[file_size] = '\0'; file_contents[file_size] = '\0';
output_value = json_parse_string(file_contents); output_value = json_parse_string(file_contents);

Loading…
Cancel
Save