From nobody Sat Sep 13 19:30:39 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cPLxC6R1sz67QCg; Sat, 13 Sep 2025 19:30:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cPLxC5vRBz3PYN; Sat, 13 Sep 2025 19:30:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757791839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iWRo3TjAdp4W9pcZzZBBE7sOBcoRGtMXqNFJF1RPtzE=; b=bex1dVPvM+sSNFms2RU5cjEVc+1Og1Cx8VwndCfGNnijrn5kvlC2RLw5+AA8qyRBOEjA2l y6I5YlY9dGCQHBB8tAD7gcNZX+Od4fBIye/zzbQmrsC9ZSBhDwYoKEYxdxcldok7yYgHdq Sh0QbDoBth6CqS5wBQ9ZBJKIGTYZJ4GkZ5oZc68XY7JHnSVaoG6QMivbnpoCxxnnX/oYiV SvNvINbFzwjfNpZ67n9PBkAdaFXx5dpoDuVVF/Qv07UlVXAWQqXMucm51p7yGdI6tZlDSa WC/gwEUR8+DCshGnjR59XgQ/qrmQr5DxBIMjGSh7DfhckIJH5Fr1tc3e6wUptQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757791839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iWRo3TjAdp4W9pcZzZBBE7sOBcoRGtMXqNFJF1RPtzE=; b=WiR5/pnkcUylRrtn2jGscQagC145Nqev3xM+w/58TwAUI6CrCZLqSgcT8yQy1hS6eo3pib ZlDzRWGx0YUoqFJ5lIq/1v6C192HS5o2KU69kbdndi47Bnb85SBEIETwKKJspxkdcVldPA 89bg+mVgrkfEdrVerPIXAg6XbmFX9/vaHWjVAMkfJbChwl/ufTcz94Adij+EnD2x048INV 3eSnN+gaaAPLVNN+cKJpgeOVrjo6hkT+rGZOKQ44BQzONAJSLLnY0XXw9STZ0H9M4YUcrk 3+kty+DoO0g7TSVyy7gKdm1zNiz0d3X93b43IkUf67sxiXmWofni2yz7FjP3jw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757791839; a=rsa-sha256; cv=none; b=N8SX9+tUP40sZ0Fe5rdNxkHe+fmSkau3QUux8JGFMuY6rEc0+4G+35ME309+ObazUdAIGO hBcWosd7IRR91LXhDhv6TXDGJFm8rYXifpBLBzkRCKIPf2O9mmT0oena0CAu+qwgykXsKL 5jjLbj2Xp3G0St4edytKKAt44iRtsMl7Xh5o2lsJN8ZvVXUlB5SHgjuML5e6UAZBuA0Ksp 2OtGiGs1pw9wVTZR0/KhiaGr0yNikJJocYcCo8p059Nm84P8s/icbq8Ehs/MmhSi7cBZ4a Cn72trwk/JhlulEAnWTdW+Nu/pDn2mk2gOyoVKY2d1HhGNxmGsv9JtLCc7aDYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cPLxC5Ghzzsbq; Sat, 13 Sep 2025 19:30:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58DJUd3l079281; Sat, 13 Sep 2025 19:30:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58DJUd8L079277; Sat, 13 Sep 2025 19:30:39 GMT (envelope-from git) Date: Sat, 13 Sep 2025 19:30:39 GMT Message-Id: <202509131930.58DJUd8L079277@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: e0eaabb80d17 - main - libc: Have memcmp test what the standard requires List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e0eaabb80d1724acf88f04acbc2ca13d42270863 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=e0eaabb80d1724acf88f04acbc2ca13d42270863 commit e0eaabb80d1724acf88f04acbc2ca13d42270863 Author: Ed Maste AuthorDate: 2024-11-20 16:47:35 +0000 Commit: Ed Maste 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);