Skip to content

memcmp() returns unexpected value #145508

Open
@8ss-boop

Description

@8ss-boop
#include <stdio.h>
#include <string.h>
int foo(const char *a, const char *b)
{
return memcmp(a,b,5);
}
int main()
{
int x=foo("HELLO C23","C23 STD");
int y=memcmp("HELLO C23","C23 STD",5);
printf("%d = %d\n",x, y);
}

At -O0 optimization level, when called through function foo(), it incorrectly returns 5 instead of 1.

5 = 1

Reproduce link:
https://godbolt.org/z/4aqY8x3TT

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions