Page MenuHomeFreeBSD

libc: Have memcmp test what's actually required by the standard
ClosedPublic

Authored by emaste on Sep 12 2025, 4:23 PM.
Tags
None
Referenced Files
F132647142: D52502.diff
Sat, Oct 18, 5:47 PM
Unknown Object (File)
Sat, Oct 11, 1:40 PM
Unknown Object (File)
Sat, Oct 11, 1:40 PM
Unknown Object (File)
Sat, Oct 11, 1:40 PM
Unknown Object (File)
Sat, Oct 11, 1:40 PM
Unknown Object (File)
Sat, Oct 11, 5:24 AM
Unknown Object (File)
Thu, Sep 25, 7:50 PM
Unknown Object (File)
Mon, Sep 22, 7:49 PM
Subscribers

Details

Summary

libc's C memcmp currently returns the difference in byte values rather than just -1/0/1 as the AArch64 assembly implementation, and many non-FreeBSD implementations, do.

It is a bug for a user to expect memcmp to return the difference in the byte values as the compiler is free to inline memcmp() with an implementation that does not do this. Change the test to validate only what the standard requires.

PR: 289084

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

emaste created this revision.
emaste added inline comments.
lib/libc/tests/string/memcmp_test.c
48
This revision is now accepted and ready to land.Sep 12 2025, 5:59 PM