[PATCH!]g++ Internal error with large IDENTIFIER length.

iko@bert2.crec.mipt.ru iko@bert2.crec.mipt.ru
Sat Feb 7 18:22:00 GMT 1998


  Hello!

[ I'm not a real g++ hacker, so substitute 'bug' with 'feature' or
  'situation' when needed :) ]

  I had not checked mailing list (if any) yet, so I think this bug might be
fixed already. The problem is: during cc1plus execution, when make_thunk()
from gcc/cp/method.c got called in a situation with large [function] names
[particulary long-named template template params] it's static buffer
of 250 chars would overflow, corrupting stack -> causing segmentation
fault -> causing Internal compiler error.
  I do not see a need for test source, AFAIK the situation is clear. But
I've saved the .ii file and will send it on requiest. On that file the
offending func_name string has length of 302 chars (AFAIR), which is
sertainly more than 250 in buffer - no good, and return stack immediately
got corrupted after sprintf().
  I think this bug is machine-independant; nevertheless I use:

 - Linux RedHat 5.0, kernel 2.0.33, glibc-2 (glibc-2.0.6-9.i386.rpm)
 - gcc -v : gcc version egcs-2.91.07 980205 (gcc-2.8.0 release)
 - libstdc++.so.2.8.0 from egcs-2.91.07 980205 snapshot.

  I have no sources for gcc-2.8.0 and egcs-1.0.1 releases, but this bug
appears to be covered by them. Both give Internal error on the same line
of test source file.
  The patch at the end of mail seems to correct the bug. I successively
used it on test source file (and many other - from ACE_wrappers package).

  As suggested by info, here you will find output of 'diff -cp' for
the changes I made. The real egcs people please optimize this, if you
find the patch worth incorporating.

  Happy compiling!!!

--
Igor V. Kovalenko   mailto:iko@crec.mipt.ru

----------PATCH FOLLOWS THIS LINE------------------------------------
*** egcs-980205/gcc/cp/method.c-980205	Sun Feb  8 03:40:19 1998
--- egcs-980205/gcc/cp/method.c	Sun Feb  8 04:12:06 1998
*************** make_thunk (function, delta)
*** 1905,1911 ****
       tree function;
       int delta;
  {
!   char buffer[250];
    tree thunk_id;
    tree thunk;
    char *func_name;
--- 1905,1912 ----
       tree function;
       int delta;
  {
!   char *buffer;
!   int  buffer_length;
    tree thunk_id;
    tree thunk;
    char *func_name;
*************** make_thunk (function, delta)
*** 1916,1921 ****
--- 1917,1927 ----
    if (TREE_CODE (func_decl) != FUNCTION_DECL)
      abort ();
    func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
+   buffer_length = strlen(func_name)+11/*of __thunk_n_*/+11/*best of int*/;
+   if (buffer_length <= 0 || (buffer=(char*)alloca(buffer_length)) == NULL) {
+     printf("malloc failed, pitty...\n");
+     abort();
+   }
    if (delta<=0)
      sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
    else



More information about the Gcc-bugs mailing list