The branch main has been updated by emaste:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e0eaabb80d1724acf88f04acbc2ca13d42270863

commit e0eaabb80d1724acf88f04acbc2ca13d42270863
Author:     Ed Maste <ema...@freebsd.org>
AuthorDate: 2024-11-20 16:47:35 +0000
Commit:     Ed Maste <ema...@freebsd.org>
CommitDate: 2025-09-13 19:30:31 +0000

    libc: Have memcmp test what the standard requires
    
    libc's C memcmp currently returns the difference in byte values rather
    than just -1/0/1 as the AArch64 assembly implementation, many non-
    FreeBSD implementations, and compiler built-in optimizations 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
    Reviewed by:    markj, fuz
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D52502
---
 lib/libc/tests/string/memcmp_test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/libc/tests/string/memcmp_test.c 
b/lib/libc/tests/string/memcmp_test.c
index 5286a0b994f3..fa2f498ccfaf 100644
--- a/lib/libc/tests/string/memcmp_test.c
+++ b/lib/libc/tests/string/memcmp_test.c
@@ -41,14 +41,14 @@
 #endif
 
 /*
- * On FreeBSD we demand that memcmp returns the difference between the
- * characters at the first site of mismatch.  However, ISO/IEC 9899:1990
- * only specifies that a number greater than, equal to, or less than
- * zero shall be returned.  If a unit test for this less strict
- * behaviour is desired, define RES(x) to be (((x) > 0) - ((x) < 0)).
+ * On FreeBSD we previously demanded that memcmp returns the difference
+ * between the characters at the first site of mismatch.  However,
+ * ISO/IEC 9899:1990 only specifies that a number greater than, equal
+ * to, or less than zero shall be returned.  If a unit test for the
+ * more strict behaviour is desired, define RES(x) to be (x).
  */
 #ifndef RES
-#define RES(x) (x)
+#define RES(x) (((x) > 0) - ((x) < 0))
 #endif
 
 static int (*memcmp_fn)(const void *, const void *, size_t);

Reply via email to