]> oss.titaniummirror.com Git - msp430-binutils.git/blobdiff - libiberty/cplus-dem.c
Imported binutils-2.20
[msp430-binutils.git] / libiberty / cplus-dem.c
index 1f8b1fc31e4b8fd5618059c17948c87c7a47c6c8..66285141ffa2ff6f6caaa4f5effa59f957bc9349 100644 (file)
@@ -52,8 +52,8 @@ Boston, MA 02110-1301, USA.  */
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #else
-char * malloc ();
-char * realloc ();
+void * malloc ();
+void * realloc ();
 #endif
 
 #include <demangle.h>
@@ -414,7 +414,7 @@ static int do_type (struct work_stuff *, const char **, string *);
 
 static int do_arg (struct work_stuff *, const char **, string *);
 
-static void
+static int
 demangle_function_name (struct work_stuff *, const char **, string *,
                         const char *);
 
@@ -984,7 +984,10 @@ ada_demangle (const char *mangled, int option ATTRIBUTE_UNUSED)
       goto Suppress;
 
   if (! changed)
-    return NULL;
+    {
+      free (demangled);
+      return NULL;
+    }
   else
     return demangled;
   
@@ -2493,10 +2496,7 @@ iterate_demangle_function (struct work_stuff *work, const char **mangled,
      "__"-sequence.  This is the normal case.  */
   if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING
       || strstr (scan + 2, "__") == NULL)
-    {
-      demangle_function_name (work, mangled, declp, scan);
-      return 1;
-    }
+    return demangle_function_name (work, mangled, declp, scan);
 
   /* Save state so we can restart if the guess at the correct "__" was
      wrong.  */
@@ -2513,10 +2513,12 @@ iterate_demangle_function (struct work_stuff *work, const char **mangled,
 
   while (scan[2])
     {
-      demangle_function_name (work, mangled, declp, scan);
-      success = demangle_signature (work, mangled, declp);
-      if (success)
-       break;
+      if (demangle_function_name (work, mangled, declp, scan))
+       {
+         success = demangle_signature (work, mangled, declp);
+         if (success)
+           break;
+       }
 
       /* Reset demangle state for the next round.  */
       *mangled = mangle_init;
@@ -4421,7 +4423,9 @@ demangle_nested_args (struct work_stuff *work, const char **mangled,
   return result;
 }
 
-static void
+/* Returns 1 if a valid function name was found or 0 otherwise.  */
+
+static int 
 demangle_function_name (struct work_stuff *work, const char **mangled,
                         string *declp, const char *scan)
 {
@@ -4461,13 +4465,13 @@ demangle_function_name (struct work_stuff *work, const char **mangled,
        {
          work -> constructor += 1;
          string_clear (declp);
-         return;
+         return 1;
        }
       else if (strcmp (declp -> b, "__dt") == 0)
        {
          work -> destructor += 1;
          string_clear (declp);
-         return;
+         return 1;
        }
     }
 
@@ -4575,6 +4579,13 @@ demangle_function_name (struct work_stuff *work, const char **mangled,
            }
        }
     }
+
+  /* If a function name was obtained but it's not valid, we were not
+     successful.  */
+  if (LEN_STRING (declp) == 1 && declp->b[0] == '.')
+    return 0;
+  else
+    return 1;
 }
 
 /* a mini string-handling package */