From 5aa21813362922e9347ffed7858389a658e33866 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 21 Jul 2015 12:02:10 +0200 Subject: [PATCH] testigddescparse.c: check fread() return value --- miniupnpc/testigddescparse.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/miniupnpc/testigddescparse.c b/miniupnpc/testigddescparse.c index c70ec6a..002a6a3 100644 --- a/miniupnpc/testigddescparse.c +++ b/miniupnpc/testigddescparse.c @@ -141,7 +141,7 @@ int main(int argc, char * * argv) FILE * f; char * buffer; int len; - int r = 0; + int r; if(argc<2) { fprintf(stderr, "Usage: %s file.xml [file.values]\n", argv[0]); return 1; @@ -160,7 +160,13 @@ int main(int argc, char * * argv) fclose(f); 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); f = NULL; if(argc > 2) {