[coreboot-gerrit] New patch to review for coreboot: 2683d41 util/genprof: improve handling of command line arguments
Daniele Forsi (dforsi@gmail.com)
gerrit at coreboot.org
Sun Aug 10 14:57:51 CEST 2014
Daniele Forsi (dforsi at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6573
-gerrit
commit 2683d41647130cfe80dc46bb648ad4caa68aec07
Author: Daniele Forsi <dforsi at gmail.com>
Date: Sun Aug 3 13:47:58 2014 +0200
util/genprof: improve handling of command line arguments
Accept only one command line argument (the input file name); close input
stream both on error and on success; print more informative error messages
when files could not be opened.
Change-Id: Ib2f0622a332317d7a13f33f1e5787381804c43a9
Found-by: missing fclose()'s found by Cppcheck 1.65
Signed-off-by: Daniele Forsi <dforsi at gmail.com>
---
util/genprof/genprof.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/util/genprof/genprof.c b/util/genprof/genprof.c
index 9fc39da..f4dd4cb 100644
--- a/util/genprof/genprof.c
+++ b/util/genprof/genprof.c
@@ -46,17 +46,21 @@ int main(int argc, char* argv[])
uint8_t tag;
uint16_t hit;
- if ( argc < 2 )
- {
+ if (argc != 2) {
fprintf(stderr, "Please specify the coreboot trace log as parameter\n");
return 1;
}
f = fopen(argv[1], "r");
- fo = fopen("gmon.out", "w+");
+ if (f == NULL) {
+ perror("Unable to open the input file");
+ return 1;
+ }
- if ((f == NULL) || (fo == NULL)) {
- fprintf(stderr, "Unable to manipulate with the input file\n");
+ fo = fopen("gmon.out", "w+");
+ if (fo == NULL) {
+ perror("Unable to open the output file");
+ fclose(f);
return 1;
}
@@ -104,5 +108,7 @@ int main(int argc, char* argv[])
}
fclose(fo);
+ fclose(f);
+
return 0;
}
More information about the coreboot-gerrit
mailing list