From 5890bc92d41b13a99c7a3349daa9a2e2162b1ce2 Mon Sep 17 00:00:00 2001
From: Jeff Law <law@gcc.gnu.org>
Date: Sun, 22 Feb 1998 09:53:40 -0700
Subject: [PATCH] cplus-dem.c (gnu_special): Don't get confused by .<digits>
 strings that are not actually lengths.

	* cplus-dem.c (gnu_special): Don't get confused by .<digits>
	strings that are not actually lengths.
	* config/mh-cygwin32: remove vasprintf.o from EXTRA_OFILES
	since it gets built automatically
	* vasprintf.c (int_vasprintf): Increase buffer size for float/double
	values.

From-SVN: r18171
---
 libiberty/ChangeLog          | 24 ++++++++++++++++--------
 libiberty/config/mh-aix      |  1 +
 libiberty/config/mh-cygwin32 |  2 +-
 libiberty/cplus-dem.c        |  9 +++++++++
 libiberty/vasprintf.c        |  5 ++++-
 5 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 43fe6dd7a96f..1e529f840ba0 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -3,6 +3,16 @@ Thu Feb 12 16:29:49 1998  Ian Lance Taylor  <ian@cygnus.com>
 	* getopt.c: Update to latest FSF version.
 	* getopt1.c: Likewise.
 
+Tue Feb 10 16:58:33 1998  Stan Shebs  <shebs@andros.cygnus.com>
+
+	* cplus-dem.c (gnu_special): Don't get confused by .<digits>
+	strings that are not actually lengths.
+
+Thu Feb  5 18:48:56 1998  Geoffrey Noer  <noer@cygnus.com>
+
+        * config/mh-cygwin32: remove vasprintf.o from EXTRA_OFILES
+        since it gets built automatically
+
 Fri Feb  6 01:35:17 1998  Manfred Hollstein  <manfred@s-direktnet.de>
 
 	* Makefile.in (FLAGS_TO_PASS): Don't pass PICFLAG.
@@ -14,6 +24,11 @@ Sun Feb  1 02:52:32 1998  Mike Stump  <mrs@wrs.com>
 	* config.table (vxworks configs): Default to VxWorks 5.x, as that is
 	the currently shipping OS.
 
+Sun Jan 18 15:57:28 1998  Michael Snyder  <msnyder@cleaver.cygnus.com>
+
+	* vasprintf.c (int_vasprintf): Increase buffer size for float/double
+	values.
+
 Sat Jan 17 22:32:38 1998  Mumit Khan  <khan@xraylith.wisc.edu>
                           J.J. VanderHeijden <J.J.vanderHeijden@student.utwente.nl>
 
@@ -39,7 +54,7 @@ Thu Dec  4 17:25:19 1997  Jeffrey A Law  (law@cygnus.com)
 Wed Nov 19 13:37:06 1997  Michael Meissner  <meissner@cygnus.com>
 
 	* alloca-norm.h (alloca, GCC case): Don't redefine alloca if it
-	was alr	eady defined previously.
+	was already defined previously.
 
 Mon Nov 10 12:48:03 1997  Philippe De Muyter  <phdm@macqel.be>
 
@@ -87,13 +102,6 @@ Sun Sep 28 12:00:52 1997  Mark Mitchell  <mmitchell@usa.net>
         (consume_count_with_underscores): New function.
         (demangle_signature): Handle new name-mangling scheme.
 
-Sun Sep 28 12:00:52 1997  Mark Mitchell  <mmitchell@usa.net>
-
-        * cplus-dem.c (demangle_template): Add new parameter.  Handle new
-        template-function mangling.
-        (consume_count_with_underscores): New function.
-        (demangle_signature): Handle new name-mangling scheme.
-
 Wed Sep 24 00:31:59 1997  Felix Lee  <flee@yin.cygnus.com>
 
 	* asprintf.c: stdarg.h when ALMOST_STDC
diff --git a/libiberty/config/mh-aix b/libiberty/config/mh-aix
index c7b848d976aa..ee84d03ff33a 100644
--- a/libiberty/config/mh-aix
+++ b/libiberty/config/mh-aix
@@ -1,3 +1,4 @@
+# This file is only needed by AIX 3.1.
 HDEFINES = -D__IEEE_BIG_ENDIAN
 RANLIB=true
 INSTALL=cp
diff --git a/libiberty/config/mh-cygwin32 b/libiberty/config/mh-cygwin32
index f45bdc8bad79..42b1afb64c03 100644
--- a/libiberty/config/mh-cygwin32
+++ b/libiberty/config/mh-cygwin32
@@ -1,2 +1,2 @@
 HDEFINES=-DNEED_sys_siglist -DNEED_basename -DNEED_strsignal
-EXTRA_OFILES=vasprintf.o random.o
+EXTRA_OFILES=random.o
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index ed16c8680cd0..f4d71238c400 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -1692,6 +1692,15 @@ gnu_special (work, mangled, declp)
 	      if (isdigit(*mangled[0]))
 		{
 		  n = consume_count(mangled);
+		  /* We may be seeing a too-large size, or else a
+		     ".<digits>" indicating a static local symbol.  In
+		     any case, declare victory and move on; *don't* try
+		     to use n to allocate.  */
+		  if (n >= strlen (*mangled))
+		    {
+		      success = 1;
+		      break;
+		    }
 		}
 	      else
 		{
diff --git a/libiberty/vasprintf.c b/libiberty/vasprintf.c
index 38e846804617..da83db2ea750 100644
--- a/libiberty/vasprintf.c
+++ b/libiberty/vasprintf.c
@@ -74,7 +74,7 @@ int_vasprintf (result, format, args)
 	    }
 	  while (strchr ("hlL", *p))
 	    ++p;
-	  /* Should be big enough for any format specifier except %s.  */
+	  /* Should be big enough for any format specifier except %s and floats.  */
 	  total_width += 30;
 	  switch (*p)
 	    {
@@ -93,6 +93,9 @@ int_vasprintf (result, format, args)
 	    case 'g':
 	    case 'G':
 	      (void) va_arg (ap, double);
+	      /* Since an ieee double can have an exponent of 307, we'll
+		 make the buffer wide enough to cover the gross case. */
+	      total_width += 307;
 	      break;
 	    case 's':
 	      total_width += strlen (va_arg (ap, char *));
-- 
GitLab