This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch/cygming]: Null terminate string returned by i386_pe_strip_name_encoding_full.

Currently, i386_pe_strip_name_encoding_full in config/i386/winnt.c,
fails to terminate the string it allocates via ggc_alloc_string. This is
fallout from the change

2008-05-21  Tom Tromey  <>

	* stringpool.c (string_stack): Remove.
	(init_stringpool): Update.
	(ggc_alloc_string): Use ggc_alloc.

Unlike the function obstack_grow0, which was used previously, gcc_alloc
does not add a terminating '\0' for us. As a result mingw32  gets bogus section
names like:
	.section	.text$_Z2f1i@¯,"x"

rather than the correct
	.section	.text$_Z2f1i,"x"

I have committed the following to fix:

2008-10-02  Danny Smith  <>

	* config/i386/winnt.c (i386_pe_strip_name_encoding_full):
	Add a null terminator to the stripped name.

Index: config/i386/winnt.c
--- config/i386/winnt.c	(revision 140821)
+++ config/i386/winnt.c	(working copy)
@@ -352,8 +352,16 @@
   /* Strip trailing "@n".  */
   p = strchr (name, '@');
   if (p)
-    return ggc_alloc_string (name, p - name);
+    {
+      /*  We need to replace the suffix with a null terminator.
+          Do that before using ggc_alloc_string to allocate the
+          const char *.  */
+      size_t len = p - name;
+      char *newname = XALLOCAVEC (char, len + 1);
+      memcpy (newname, name, len);
+      newname [len] = 0;
+      return ggc_alloc_string  (newname, len);
+    }
   return name;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]