Skip to content

Bug: libc implementation of strcasestr() doesn't work correctly #1323

@Funny-ppt

Description

@Funny-ppt

Contact Details

[email protected]

What happened?

cosmoplitian libc strcasestr() return 0 for below example

#ifdef __COSMOPOLITIAN__
#include <libc/str/str.h>
#endif
#include <stdio.h>

int main() {
  printf("strcasestr(\"Windows\", \"win\") = %llu", strcasestr("Windows", "win"));
}

Version

cosmocc (GCC) 14.1.0

What operating system are you seeing the problem on?

both on x86_64 windows/linux

Relevant log output

(venv) ➜  backend git:(fastdev) ✗ $CC -D_COSMO_SOURCE testb.c -o testb
(venv) ➜  backend git:(fastdev) ✗ ./testb
strcasestr("Windows", "win") = 0%                                                                                                                                                                                                                                                                   
(venv) ➜  backend git:(fastdev) ✗ cc testb.c -o testb                                                                                                                                                                                                                           
testb.c: In function ‘main’:
testb.c:7:53: warning: implicit declaration of function ‘strcasestr’ [-Wimplicit-function-declaration]
    7 |   printf("strcasestr(\"Windows\", \"win\") = %llu", strcasestr("Windows", "win"));
      |                                                     ^~~~~~~~~~
(venv) ➜  backend git:(fastdev) ✗ ./testb
strcasestr("Windows", "win") = 3786059788%

note $CC refers cosmocc

Metadata

Metadata

Assignees

No one assigned

    Labels

    medium severityUsed to report medium severity bugs (e.g. Malfunctioning Features but still useable)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions