diff options
author | Ben Elliston <bje@au.ibm.com> | 2007-01-15 23:26:08 +0000 |
---|---|---|
committer | Ben Elliston <bje@au.ibm.com> | 2007-01-15 23:26:08 +0000 |
commit | 74335607500eaa6894aa7dc8c103d73a85758504 (patch) | |
tree | 11a009888622efdaf7a5e537732a11df2bc1b016 | |
parent | 1cee0bf24eeed8b06e8c07ccd23b3d5a25cfcc74 (diff) | |
download | fsf-binutils-gdb-74335607500eaa6894aa7dc8c103d73a85758504.zip fsf-binutils-gdb-74335607500eaa6894aa7dc8c103d73a85758504.tar.gz fsf-binutils-gdb-74335607500eaa6894aa7dc8c103d73a85758504.tar.bz2 |
* corefile.c (parse_error): New function.
(read_function_mappings): Check calls to fscanf and report any
errors in parsing the mapping file.
-rw-r--r-- | gprof/ChangeLog | 6 | ||||
-rw-r--r-- | gprof/corefile.c | 35 |
2 files changed, 27 insertions, 14 deletions
diff --git a/gprof/ChangeLog b/gprof/ChangeLog index a3ac41f..85cbbf6 100644 --- a/gprof/ChangeLog +++ b/gprof/ChangeLog @@ -1,3 +1,9 @@ +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. + 2006-12-12 Daniel Jacobowitz <dan@codesourcery.com> * Makefile.am (gprof_TEXINFOS): Set. diff --git a/gprof/corefile.c b/gprof/corefile.c index a8620ef..0d90b06 100644 --- a/gprof/corefile.c +++ b/gprof/corefile.c @@ -53,6 +53,13 @@ extern void sparc_find_call (Sym *, bfd_vma, bfd_vma); 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 *filename) 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 *filename) 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 *filename) 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); |