PR gprof/20499
* corefile.c (BUFSIZE): Define.
(STR_BUFSIZE): Define.
(read_function_mappings): Use BUFSIZE and STR)BUFSIZE.
(num_of_syms_in): Move buf, address and name arrays out of
function and declare as static BUFSIZE arrays.
Use STR_BUFSIZE when scanning for name and address.
(core_create_syms_from): Revert previous delta. Instead
short circuit the parsing of a symbol if all three fields
could not be found.
+2016-08-23 Nick Clifton <nickc@redhat.com>
+
+ PR gprof/20499
+ * corefile.c (BUFSIZE): Define.
+ (STR_BUFSIZE): Define.
+ (read_function_mappings): Use BUFSIZE and STR)BUFSIZE.
+ (num_of_syms_in): Move buf, address and name arrays out of
+ function and declare as static BUFSIZE arrays.
+ Use STR_BUFSIZE when scanning for name and address.
+ (core_create_syms_from): Revert previous delta. Instead
+ short circuit the parsing of a symbol if all three fields
+ could not be found.
+
2016-08-22 Nick Clifton <nickc@redhat.com>
PR gprof/20499
2016-08-22 Nick Clifton <nickc@redhat.com>
PR gprof/20499
((struct function_map *) r)->function_name);
}
((struct function_map *) r)->function_name);
}
+#define BUFSIZE (1024)
+/* This is BUFSIZE - 1 as a string. Suitable for use in fprintf/sscanf format strings. */
+#define STR_BUFSIZE "1023"
+
static void
read_function_mappings (const char *filename)
{
FILE * file = fopen (filename, "r");
static void
read_function_mappings (const char *filename)
{
FILE * file = fopen (filename, "r");
int count = 0;
unsigned int i;
int count = 0;
unsigned int i;
- matches = fscanf (file, "%[^\n:]", dummy);
+ matches = fscanf (file, "%" STR_BUFSIZE "[^\n:]", dummy);
if (!matches)
parse_error (filename);
if (!matches)
parse_error (filename);
}
/* Don't care what else is on this line at this point. */
}
/* Don't care what else is on this line at this point. */
- matches = fscanf (file, "%[^\n]\n", dummy);
+ matches = fscanf (file, "%" STR_BUFSIZE "[^\n]\n", dummy);
if (!matches)
parse_error (filename);
count++;
if (!matches)
parse_error (filename);
count++;
- matches = fscanf (file, "%[^\n:]", dummy);
+ matches = fscanf (file, "%" STR_BUFSIZE "[^\n:]", dummy);
if (!matches)
parse_error (filename);
if (!matches)
parse_error (filename);
strcpy (symbol_map[count].file_name, dummy);
/* Now we need the function name. */
strcpy (symbol_map[count].file_name, dummy);
/* Now we need the function name. */
- matches = fscanf (file, "%[^\n]\n", dummy);
+ matches = fscanf (file, "%" STR_BUFSIZE "[^\n]\n", dummy);
if (!matches)
parse_error (filename);
tmp = strrchr (dummy, ' ') + 1;
if (!matches)
parse_error (filename);
tmp = strrchr (dummy, ' ') + 1;
+static char buf[BUFSIZE];
+static char address[BUFSIZE];
+static char name[BUFSIZE];
+
/* Return number of symbols in a symbol-table file. */
static int
num_of_syms_in (FILE * f)
{
/* Return number of symbols in a symbol-table file. */
static int
num_of_syms_in (FILE * f)
{
- const int BUFSIZE = 1024;
- char * buf = (char *) xmalloc (BUFSIZE);
- char * address = (char *) xmalloc (BUFSIZE);
- char * name = (char *) xmalloc (BUFSIZE);
int num = 0;
while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
{
int num = 0;
while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
{
- if (sscanf (buf, "%s %c %s", address, &type, name) == 3)
+ if (sscanf (buf, "%" STR_BUFSIZE "s %c %" STR_BUFSIZE "s", address, &type, name) == 3)
if (type == 't' || type == 'T')
++num;
}
if (type == 't' || type == 'T')
++num;
}
- free (buf);
- free (address);
- free (name);
-
void
core_create_syms_from (const char * sym_table_file)
{
void
core_create_syms_from (const char * sym_table_file)
{
- const int BUFSIZE = 1024;
- char * buf = (char *) xmalloc (BUFSIZE);
- char * address = (char *) xmalloc (BUFSIZE);
- char * name = (char *) xmalloc (BUFSIZE);
bfd_vma min_vma = ~(bfd_vma) 0;
bfd_vma max_vma = 0;
FILE * f;
bfd_vma min_vma = ~(bfd_vma) 0;
bfd_vma max_vma = 0;
FILE * f;
while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
{
while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
{
- if (sscanf (buf, "%s %c %s", address, &type, name) == 3)
- if (type != 't' && type != 'T')
- continue;
-
- /* PR 20499 */
- if ((symtab.limit - symtab.base) >= symtab.len)
- {
- fprintf (stderr, _("%s: too many symbols in file '%s'\n"), whoami, sym_table_file);
- done (1);
- }
+ if (sscanf (buf, "%" STR_BUFSIZE "s %c %" STR_BUFSIZE "s", address, &type, name) != 3)
+ continue;
+ if (type != 't' && type != 'T')
+ continue;
symtab.len = symtab.limit - symtab.base;
symtab_finalize (&symtab);
symtab.len = symtab.limit - symtab.base;
symtab_finalize (&symtab);
-
- free (buf);
- free (address);
- free (name);