This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: silence warnings in gprof/corefile.c
Hi Nick
> > * corefile.c (read_function_mappings): Check calls to fscanf and
> > report any errors in parsing the mapping file.
>
> Approved - please apply - although since you are repeating the same
> block of code four times, wouldn't it be easier to put the new code into
> a function or macro and just call that four times ?
I was deliberating over that. :-) Here's what I'm committing:
2007-01-16 Ben Elliston <bje@au.ibm.com>
* corefile.c (parse_error): New function.
(read_function_mappings): Check calls to fscanf and report any
errors in parsing the mapping file.
Index: corefile.c
===================================================================
RCS file: /cvs/src/src/gprof/corefile.c,v
retrieving revision 1.24
diff -u -p -r1.24 corefile.c
--- corefile.c 22 Mar 2006 03:51:02 -0000 1.24
+++ corefile.c 15 Jan 2007 23:24:39 -0000
@@ -53,6 +53,13 @@ extern void sparc_find_call (Sym *, bfd_
extern void mips_find_call (Sym *, bfd_vma, bfd_vma);
static void
+parse_error (const char *filename)
+{
+ fprintf (stderr, _("%s: unable to parse mapping file %s.\n"), whoami, filename);
+ done (1);
+}
+
+static void
read_function_mappings (const char *filename)
{
FILE *file = fopen (filename, "r");
@@ -74,21 +81,21 @@ read_function_mappings (const char *file
matches = fscanf (file, "%[^\n:]", dummy);
if (!matches)
- {
- fprintf (stderr, _("%s: unable to parse mapping file %s.\n"),
- whoami, filename);
- done (1);
- }
+ parse_error (filename);
/* Just skip messages about files with no symbols. */
if (!strncmp (dummy, "No symbols in ", 14))
{
- fscanf (file, "\n");
+ matches = fscanf (file, "\n");
+ if (matches == EOF)
+ parse_error (filename);
continue;
}
/* Don't care what else is on this line at this point. */
- fscanf (file, "%[^\n]\n", dummy);
+ matches = fscanf (file, "%[^\n]\n", dummy);
+ if (!matches)
+ parse_error (filename);
count++;
}
@@ -108,16 +115,14 @@ read_function_mappings (const char *file
matches = fscanf (file, "%[^\n:]", dummy);
if (!matches)
- {
- fprintf (stderr, _("%s: unable to parse mapping file %s.\n"),
- whoami, filename);
- done (1);
- }
+ parse_error (filename);
/* Just skip messages about files with no symbols. */
if (!strncmp (dummy, "No symbols in ", 14))
{
- fscanf (file, "\n");
+ matches = fscanf (file, "\n");
+ if (matches == EOF)
+ parse_error (filename);
continue;
}
@@ -126,7 +131,9 @@ read_function_mappings (const char *file
strcpy (symbol_map[count].file_name, dummy);
/* Now we need the function name. */
- fscanf (file, "%[^\n]\n", dummy);
+ matches = fscanf (file, "%[^\n]\n", dummy);
+ if (!matches)
+ parse_error (filename);
tmp = strrchr (dummy, ' ') + 1;
symbol_map[count].function_name = xmalloc (strlen (tmp) + 1);
strcpy (symbol_map[count].function_name, tmp);