testigddescparse.c: check fread() return value

This commit is contained in:
Thomas Bernard 2015-07-21 12:02:10 +02:00
parent 7ee1dd097c
commit 5aa2181336
1 changed files with 8 additions and 2 deletions

View File

@ -141,7 +141,7 @@ int main(int argc, char * * argv)
FILE * f; FILE * f;
char * buffer; char * buffer;
int len; int len;
int r = 0; int r;
if(argc<2) { if(argc<2) {
fprintf(stderr, "Usage: %s file.xml [file.values]\n", argv[0]); fprintf(stderr, "Usage: %s file.xml [file.values]\n", argv[0]);
return 1; return 1;
@ -160,7 +160,13 @@ int main(int argc, char * * argv)
fclose(f); fclose(f);
return 1; return 1;
} }
fread(buffer, 1, len, f); r = (int)fread(buffer, 1, len, f);
if(r != len) {
fprintf(stderr, "Failed to read file %s. %d out of %d bytes.\n",
argv[1], r, len);
fclose(f);
return 1;
}
fclose(f); fclose(f);
f = NULL; f = NULL;
if(argc > 2) { if(argc > 2) {