Re: bugs in strlen, strstr setlocale -- i386

Nikola Vladov <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
On Fri, Apr 03, 2009 at 06:05:29PM +0200, Frank Bergmann wrote:
Hi Frank!

> at least 32-Bit Intel-Arch should not segfault due to jecxz:
> > cat dietlibc-0.31/i386/strlen.S
> [...]
> strlen:
>         movl    4(%esp),%ecx
>         xorl    %eax,%eax
>         jecxz   .Lnull
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...

You are right!  I know about this line above.

vladov@picard:4 /tmp$ cat t.c               
#include <string.h>

int main() {
  return strlen((char *)0);
}

vladov@picard:4 /tmp$ diet -Os gcc -Wall t.c
t.c: In function 'main':
t.c:4: warning: null argument where non-null required (argument 1)
vladov@picard:4 /tmp$ ./a.out 
Segmentation fault (core dumped)

vladov@picard:4 /tmp$ diet gcc -Wall -O2 t.c
t.c: In function 'main':
t.c:4: warning: null argument where non-null required (argument 1)
vladov@picard:4 /tmp$ ./a.out 
vladov@picard:4 /tmp$ echo $?
0

Seems that strlen works bad with diet -Os.  At least on i386
with my compiler.  What should strlen(NULL) return?

POSIX says nothing, true?

Nikola

Seems that gcc makes the things wrong with -Os!

diet -Os gcc -S -Wall t.c
t.c: In function 'main':
t.c:4: warning: null argument where non-null required (argument 1)
cat t.s
...
        .text
.globl main
        .type   main, @function
main:
        cld
        pushl   %edi
        xorl    %eax, %eax
        xorl    %edi, %edi
        orl     $-1, %ecx
        repnz
        scasb
        popl    %edi
        notl    %ecx
        leal    -1(%ecx), %eax
        ret
...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.