This is the mail archive of the gcc-bugs@gcc.gnu.org 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]

strcpy core dumps


Dear GNU Maintainers:

I'm befuddled.  The strcpy function is core dumping and I haven't a clue.  I'm using glibc-2.1.3 and gcc-2.95.2 on a Red Hat 6.2 system.  I don't recalling updating any packages within a month or two and I'm certain strcpy was working not long ago.

My perfectly legitimate, simple little test program:

#include <stdio.h>
#include <string.h>

int main (void)
{
  char* text = "this is some text";

  (void) strcpy (text, "this is new text");
  (void) puts (text);

  return (0);
}

My debugging examination (gdb-4.18):

GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) break main
Breakpoint 1 at 0x8048426: file test01.c, line 7.
(gdb) run
Starting program: /home/elemings/dnd3e/dnd3e-0.0.6/test/test01

Breakpoint 1, main () at test01.c:7
7         char* text = "this is some text";
(gdb) n
9         (void) strcpy (text, "this is new text");
(gdb) s
strcpy (dest=0x80484b8 "this is some text", src=0x80484ca "this is new text")
    at ../sysdeps/generic/strcpy.c:33
warning: Source file is more recent than executable.

33        const ptrdiff_t off = dest - src - 1;
(gdb) n
37            c = *s++;
(gdb) print off
$1 = -19
(gdb) n
38            s[off] = c;
(gdb) print c
$2 = 116 't'
(gdb) print *s
$3 = 104 'h'
(gdb) print s[-19]
$4 = 116 't'
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
strcpy (dest=0x80484b8 "this is some text", src=0x80484ca "this is new text")
    at ../sysdeps/generic/strcpy.c:38
38            s[off] = c;
(gdb)

What can you make of it?

Thanks,
Eric.


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