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@gmail.com> Reviewed-on: http://review.coreboot.org/6573 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
parent
21fbc08d4b
commit
ea70a5068f
|
@ -46,17 +46,21 @@ int main(int argc, char* argv[])
|
||||||
uint8_t tag;
|
uint8_t tag;
|
||||||
uint16_t hit;
|
uint16_t hit;
|
||||||
|
|
||||||
if ( argc < 2 )
|
if (argc != 2) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Please specify the coreboot trace log as parameter\n");
|
fprintf(stderr, "Please specify the coreboot trace log as parameter\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fopen(argv[1], "r");
|
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)) {
|
fo = fopen("gmon.out", "w+");
|
||||||
fprintf(stderr, "Unable to manipulate with the input file\n");
|
if (fo == NULL) {
|
||||||
|
perror("Unable to open the output file");
|
||||||
|
fclose(f);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,5 +108,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fo);
|
fclose(fo);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue