Add error checking to all file functions
authorLoïMinier <loic.minier@linaro.org>
Mon, 14 Mar 2011 07:31:53 +0000 (13:01 +0530)
committerAnand Gadiyar <gadiyar@ti.com>
Mon, 14 Mar 2011 08:22:28 +0000 (13:52 +0530)
When building with a fortify-enabled toolchain, one would get:
scripts/signGP.c:305:8: warning: ignoring return value of .fread., declared with attribute warn_unused_result

Signed-off-by: LoïMinier <loic.minier@linaro.org>
Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
scripts/signGP.c

index a57124a..ab4715c 100644 (file)
@@ -290,17 +290,24 @@ int main(int argc, char *argv[])
        }
 
        if (ch_add)
-               fwrite(&config_header, 1, 512, ofile);
+               if (fwrite(&config_header, 1, 512, ofile) <= 0)
+                       pdie("fwrite");
 
-       fwrite(&len, 1, 4, ofile);
-       fwrite(&loadaddr, 1, 4, ofile);
+       if (fwrite(&len, 1, 4, ofile) <= 0)
+               pdie("fwrite");
+       if (fwrite(&loadaddr, 1, 4, ofile) <= 0)
+               pdie("fwrite");
        for (i = 0; i < len; i++) {
-               fread(&ch, 1, 1, ifile);
-               fwrite(&ch, 1, 1, ofile);
+               if (fread(&ch, 1, 1, ifile) <= 0)
+                   pdie("fread");
+               if (fwrite(&ch, 1, 1, ofile) <= 0)
+                   pdie("fwrite");
        }
 
-       fclose(ifile);
-       fclose(ofile);
+       if (!fclose(ifile))
+               perror("warning: fclose");
+       if (!fclose(ofile))
+               perror("warning: fclose");
 
        return 0;
 }