public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39166]  New: strlen() crashes with sigsegv on ubuntu 8.10
@ 2009-02-12 10:54 ajrobb at bigfoot dot com
  2009-02-12 10:59 ` [Bug c/39166] " ajrobb at bigfoot dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ajrobb at bigfoot dot com @ 2009-02-12 10:54 UTC (permalink / raw)
  To: gcc-bugs

I can print a string with printf("%s", str) but strlen(str) in the next
statement fails with Segment fault.

$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12) 

"gcc -g soundex.c -S" gives the following assembler for the 2 calls:
        .loc 1 57 0
        movl    stderr, %edx
        movl    8(%ebp), %eax
        movl    %eax, 8(%esp)
        movl    $.LC7, 4(%esp)
        movl    %edx, (%esp)
        call    fprintf
        .loc 1 58 0
        movl    8(%ebp), %eax
        movl    %eax, (%esp)
        call    strlen
        addl    8(%ebp), %eax
        movl    %eax, 12(%ebp)

"gcc -O3 -fomit-frame-pointer soundex.c -S" gives:
        movl    stderr, %eax
        movl    %esi, 12(%esp)
        movl    $.LC0, 8(%esp)
        movl    $1, 4(%esp)
        movl    %eax, (%esp)
        call    __fprintf_chk
        movl    %esi, (%esp)
        call    strlen
        leal    (%esi,%eax), %edi

Strangely, this optimised code works fine.


-- 
           Summary: strlen() crashes with sigsegv on ubuntu 8.10
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ajrobb at bigfoot dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39166


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/39166] strlen() crashes with sigsegv on ubuntu 8.10
  2009-02-12 10:54 [Bug c/39166] New: strlen() crashes with sigsegv on ubuntu 8.10 ajrobb at bigfoot dot com
@ 2009-02-12 10:59 ` ajrobb at bigfoot dot com
  2009-02-12 11:27 ` ajrobb at bigfoot dot com
  2009-02-13  4:05 ` ajrobb at bigfoot dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ajrobb at bigfoot dot com @ 2009-02-12 10:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ajrobb at bigfoot dot com  2009-02-12 10:58 -------
Created an attachment (id=17285)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17285&action=view)
small test file

run as:
./soundex burroughs ashcraft brc mcknight mcnaught mcknawt

The optimised code produces:
strlen("burroughs")
B620 burroughs
strlen("ashcraft")
A261 ashcraft
strlen("brc")
B620 brc
strlen("mcknight")
M252 mcknight
strlen("mcnaught")
M252 mcnaught
strlen("mcknawt")
M253 mcknawt

The debug code produces:
strlen("burroughs")
B620 burroughs
strlen("ashcraft")
Segmentation fault


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39166


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/39166] strlen() crashes with sigsegv on ubuntu 8.10
  2009-02-12 10:54 [Bug c/39166] New: strlen() crashes with sigsegv on ubuntu 8.10 ajrobb at bigfoot dot com
  2009-02-12 10:59 ` [Bug c/39166] " ajrobb at bigfoot dot com
@ 2009-02-12 11:27 ` ajrobb at bigfoot dot com
  2009-02-13  4:05 ` ajrobb at bigfoot dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ajrobb at bigfoot dot com @ 2009-02-12 11:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ajrobb at bigfoot dot com  2009-02-12 11:26 -------
I have tested the assembler outputs from the two compilers. Both assembler
files were generated with:
gcc -g soundex.c -S -o soundex.s

I then compiled both on the failing platform:
gcc -g soundex.s -o soundex

If I compile the assembler from 4.2.1 with 4.3.2, the program works.

If I compile the assembler from 4.3.2 with 4.3.2, the program fails.


-- 

ajrobb at bigfoot dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.3.2
      Known to work|                            |4.2.1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39166


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/39166] strlen() crashes with sigsegv on ubuntu 8.10
  2009-02-12 10:54 [Bug c/39166] New: strlen() crashes with sigsegv on ubuntu 8.10 ajrobb at bigfoot dot com
  2009-02-12 10:59 ` [Bug c/39166] " ajrobb at bigfoot dot com
  2009-02-12 11:27 ` ajrobb at bigfoot dot com
@ 2009-02-13  4:05 ` ajrobb at bigfoot dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ajrobb at bigfoot dot com @ 2009-02-13  4:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from ajrobb at bigfoot dot com  2009-02-13 04:05 -------
Many apologies. The bug was in line 66 of my code: should read:

while (src < end && dst < lim) {

This was polluting the stack - hardly surprising it crashed!


-- 

ajrobb at bigfoot dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39166


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-13  4:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-12 10:54 [Bug c/39166] New: strlen() crashes with sigsegv on ubuntu 8.10 ajrobb at bigfoot dot com
2009-02-12 10:59 ` [Bug c/39166] " ajrobb at bigfoot dot com
2009-02-12 11:27 ` ajrobb at bigfoot dot com
2009-02-13  4:05 ` ajrobb at bigfoot dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).