* objdump.c (disassemble_data): Initialize prevline to 0. Make
authorIan Lance Taylor <ian@airs.com>
Wed, 14 Sep 1994 20:21:21 +0000 (20:21 +0000)
committerIan Lance Taylor <ian@airs.com>
Wed, 14 Sep 1994 20:21:21 +0000 (20:21 +0000)
prev_function non const.  Copy functionname into an malloc buffer
when setting prev_function, instead of assuming that the string
will last forever.

binutils/ChangeLog
binutils/objdump.c

index 727c1d895a7b3b6eca8d92c43fa5276bef0597d5..35cca2c5acb62d93729e705f0c9e4694aa8d5f7b 100644 (file)
@@ -1,5 +1,10 @@
 Wed Sep 14 12:19:07 1994  Ian Lance Taylor  (ian@sanguine.cygnus.com)
 
+       * objdump.c (disassemble_data): Initialize prevline to 0.  Make
+       prev_function non const.  Copy functionname into an malloc buffer
+       when setting prev_function, instead of assuming that the string
+       will last forever.
+
        * nm.c: Include libiberty.h.
        (sort_by_size): New static variable.
        (long_options): Add --size-sort.
index 7f0c9f9a8e8d8089022377190efb19c4cfb60661..b158c53d10170714dfceeef51bb999835cf4d385 100644 (file)
@@ -451,8 +451,8 @@ disassemble_data (abfd)
   struct disassemble_info disasm_info;
   struct objdump_disasm_info aux;
 
-  int prevline;
-  CONST char *prev_function = "";
+  int prevline = 0;
+  char *prev_function = NULL;
 
   asection *section;
 
@@ -561,11 +561,16 @@ disassemble_data (abfd)
                                             &functionname,
                                             &line))
                    {
-                     if (functionname && *functionname
-                         && strcmp(functionname, prev_function))
+                     if (functionname
+                         && *functionname != '\0'
+                         && (prev_function == NULL
+                             || strcmp (functionname, prev_function) != 0))
                        {
                          printf ("%s():\n", functionname);
-                         prev_function = functionname;
+                         if (prev_function != NULL)
+                           free (prev_function);
+                         prev_function = xmalloc (strlen (functionname) + 1);
+                         strcpy (prev_function, functionname);
                        }
                      if (!filename)
                        filename = "???";