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
Unknown Object (File)
Mon, Aug 24, 11:48 AM
Unknown Object (File)
Sat, Aug 22, 4:14 PM
Unknown Object (File)
Sat, Aug 22, 4:12 PM
Unknown Object (File)
Sat, Aug 22, 4:11 PM
Unknown Object (File)
Thu, Aug 13, 1:53 AM
Unknown Object (File)
Mon, Aug 10, 7:50 AM
Unknown Object (File)
Sat, Aug 8, 3:07 AM
Unknown Object (File)
Fri, Aug 7, 2:34 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