[PATCH] Fix output_file_names crash

Ulrich Weigand Ulrich.Weigand@de.ibm.com
Fri Jan 17 18:53:00 GMT 2003


Hello,

output_file_names (dwarf2out.c) crashes on s390 when compiling a file
without any function definitions.  The reason is that

  files = (struct file_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
                                       * sizeof (struct file_info));
[...]
  files[1].dir_idx = 0;

clobbers the stack if file_table is empty.

The following patch fixes the crash by just doing nothing if
output_file_names is called with empty file_table.

Bootstrapped/regtested on s390-ibm-linux.  OK to apply?

ChangeLog:

        * dwarf2out (output_file_names): Don't crash if called
        with empty file_table.

Index: gcc/dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.394
diff -c -p -r1.394 dwarf2out.c
*** gcc/dwarf2out.c     17 Jan 2003 02:34:04 -0000      1.394
--- gcc/dwarf2out.c     17 Jan 2003 17:44:44 -0000
*************** output_file_names ()
*** 7291,7296 ****
--- 7291,7300 ----
    size_t i;
    int idx;

+   /* Nothing to do if file_table is empty.  */
+   if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
+     return;
+
    /* Allocate the various arrays we need.  */
    files = (struct file_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
                                       * sizeof (struct file_info));


Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

--
  Dr. Ulrich Weigand
  Linux for S/390 Design & Development
  IBM Deutschland Entwicklung GmbH, Schoenaicher Str. 220, 71032 Boeblingen
  Phone: +49-7031/16-3727   ---   Email: Ulrich.Weigand@de.ibm.com




More information about the Gcc-patches mailing list