- Add testcases for abs(), labs(), and llabs() functions.
- Backport: stdlib: Add testcases for abs(). (BZ #30263) - Backport: stdlib: Add testcases for labs(). (BZ #30263) - Backport: stdlib: Add testcases for llabs(). (BZ #30263) - Backport: stdlib: Use long long int in stdlib/tst-llabs - Backport: stdlib: Avoid undefined behavior in stdlib/tst-labs Resolves: RHEL-77082
This commit is contained in:
parent
8656f60248
commit
f52eb641bd
87
glibc-RHEL-77082-1.patch
Normal file
87
glibc-RHEL-77082-1.patch
Normal file
@ -0,0 +1,87 @@
|
||||
commit 0d21b3783f49ae94207a1bb9acd5dc8b071f0b13
|
||||
Author: Joe Simmons-Talbott <josimmon@redhat.com>
|
||||
Date: Tue Apr 4 09:57:45 2023 -0400
|
||||
|
||||
stdlib: Add testcases for abs(). (BZ #30263)
|
||||
|
||||
Test minimum and maximum int values, zero, and part of the range
|
||||
of int values. Use '-fno-builtin' to ensure we are testing the
|
||||
implementation.
|
||||
|
||||
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
|
||||
|
||||
Conflicts:
|
||||
stdlib/Makefile (fixup context)
|
||||
|
||||
diff --git a/stdlib/Makefile b/stdlib/Makefile
|
||||
index 4f5de988cee07932..9eb6e1b6ee1df080 100644
|
||||
--- a/stdlib/Makefile
|
||||
+++ b/stdlib/Makefile
|
||||
@@ -86,6 +86,7 @@ tests := \
|
||||
testmb2 \
|
||||
testrand \
|
||||
testsort \
|
||||
+ tst-abs \
|
||||
tst-at_quick_exit \
|
||||
tst-atexit \
|
||||
tst-atof1 \
|
||||
@@ -174,6 +175,8 @@ LDLIBS-test-dlclose-exit-race = $(shared-thread-library)
|
||||
LDFLAGS-test-dlclose-exit-race = $(LDFLAGS-rdynamic)
|
||||
LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library)
|
||||
|
||||
+CFLAGS-tst-abs.c += -fno-builtin
|
||||
+
|
||||
ifeq ($(have-cxx-thread_local),yes)
|
||||
CFLAGS-tst-quick_exit.o = -std=c++11
|
||||
LDLIBS-tst-quick_exit = -lstdc++
|
||||
diff --git a/stdlib/tst-abs.c b/stdlib/tst-abs.c
|
||||
new file mode 100644
|
||||
index 0000000000000000..2b96aedc3e2c0eef
|
||||
--- /dev/null
|
||||
+++ b/stdlib/tst-abs.c
|
||||
@@ -0,0 +1,45 @@
|
||||
+/* Basic tests for abs.
|
||||
+ Copyright (C) 2023 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <https://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#include <limits.h>
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+#include <support/check.h>
|
||||
+
|
||||
+#define LARGE_PRIME 49999
|
||||
+
|
||||
+static int do_test (void)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ TEST_COMPARE(abs(INT_MAX), INT_MAX);
|
||||
+ TEST_COMPARE(abs(INT_MIN + 1), INT_MAX);
|
||||
+ TEST_COMPARE(abs(-1), 1);
|
||||
+ TEST_COMPARE(abs(0), 0);
|
||||
+ TEST_COMPARE(abs(1), 1);
|
||||
+
|
||||
+ for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(abs(i), -i);
|
||||
+
|
||||
+ for (i = 0; i < INT_MAX - LARGE_PRIME; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(abs(i), i);
|
||||
+
|
||||
+ return EXIT_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+#include <support/test-driver.c>
|
||||
89
glibc-RHEL-77082-2.patch
Normal file
89
glibc-RHEL-77082-2.patch
Normal file
@ -0,0 +1,89 @@
|
||||
commit b11db301e162480d1812937ab0410dc7585f423c
|
||||
Author: Joe Simmons-Talbott <josimmon@redhat.com>
|
||||
Date: Tue Apr 4 09:57:46 2023 -0400
|
||||
|
||||
stdlib: Add testcases for labs(). (BZ #30263)
|
||||
|
||||
Test minimum and maximum long values, zero, and part of the range
|
||||
of long values. Use '-fno-builtin' to ensure we are testing the
|
||||
implementation.
|
||||
|
||||
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
|
||||
|
||||
diff --git a/stdlib/Makefile b/stdlib/Makefile
|
||||
index 9eb6e1b6ee1df080..2bc09c76ffea39e4 100644
|
||||
--- a/stdlib/Makefile
|
||||
+++ b/stdlib/Makefile
|
||||
@@ -106,6 +106,7 @@ tests := \
|
||||
tst-getenv-thread \
|
||||
tst-getenv-unsetenv \
|
||||
tst-getrandom \
|
||||
+ tst-labs \
|
||||
tst-limits \
|
||||
tst-makecontext \
|
||||
tst-makecontext-align \
|
||||
@@ -176,6 +177,7 @@ LDFLAGS-test-dlclose-exit-race = $(LDFLAGS-rdynamic)
|
||||
LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library)
|
||||
|
||||
CFLAGS-tst-abs.c += -fno-builtin
|
||||
+CFLAGS-tst-labs.c += -fno-builtin
|
||||
|
||||
ifeq ($(have-cxx-thread_local),yes)
|
||||
CFLAGS-tst-quick_exit.o = -std=c++11
|
||||
diff --git a/stdlib/tst-labs.c b/stdlib/tst-labs.c
|
||||
new file mode 100644
|
||||
index 0000000000000000..92b456745ac1bb2d
|
||||
--- /dev/null
|
||||
+++ b/stdlib/tst-labs.c
|
||||
@@ -0,0 +1,51 @@
|
||||
+/* Basic tests for labs.
|
||||
+ Copyright (C) 2023 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <https://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#include <limits.h>
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+#include <support/check.h>
|
||||
+
|
||||
+#define LARGE_PRIME 49999
|
||||
+
|
||||
+static int do_test (void)
|
||||
+{
|
||||
+ long i;
|
||||
+
|
||||
+ TEST_COMPARE(labs(LONG_MAX), LONG_MAX);
|
||||
+ TEST_COMPARE(labs(LONG_MIN + 1), LONG_MAX);
|
||||
+ TEST_COMPARE(labs(-1), 1);
|
||||
+ TEST_COMPARE(labs(0), 0);
|
||||
+ TEST_COMPARE(labs(1), 1);
|
||||
+
|
||||
+ for (i = LONG_MIN + 1; i < LONG_MIN + INT_MAX; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(labs(i), -i);
|
||||
+
|
||||
+ for (i = LONG_MAX - INT_MAX; i < LONG_MAX - LARGE_PRIME; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(labs(i), i);
|
||||
+
|
||||
+ for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(labs(i), -i);
|
||||
+
|
||||
+ for (i = 0; i < INT_MAX; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(labs(i), i);
|
||||
+
|
||||
+ return EXIT_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+#include <support/test-driver.c>
|
||||
93
glibc-RHEL-77082-3.patch
Normal file
93
glibc-RHEL-77082-3.patch
Normal file
@ -0,0 +1,93 @@
|
||||
commit d877b52d58b1c73810751bdb48987b84bda87d5e
|
||||
Author: Joe Simmons-Talbott <josimmon@redhat.com>
|
||||
Date: Tue Apr 4 09:57:47 2023 -0400
|
||||
|
||||
stdlib: Add testcases for llabs(). (BZ #30263)
|
||||
|
||||
Test minimum and maximum long long values, zero, 32bit crossover points, and
|
||||
part of the range of long long values. Use '-fno-builtin' to ensure we are
|
||||
testing the implementation.
|
||||
|
||||
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
|
||||
|
||||
diff --git a/stdlib/Makefile b/stdlib/Makefile
|
||||
index 2bc09c76ffea39e4..fe43bec0f9d581d5 100644
|
||||
--- a/stdlib/Makefile
|
||||
+++ b/stdlib/Makefile
|
||||
@@ -108,6 +108,7 @@ tests := \
|
||||
tst-getrandom \
|
||||
tst-labs \
|
||||
tst-limits \
|
||||
+ tst-llabs \
|
||||
tst-makecontext \
|
||||
tst-makecontext-align \
|
||||
tst-makecontext2 \
|
||||
@@ -178,6 +179,7 @@ LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library)
|
||||
|
||||
CFLAGS-tst-abs.c += -fno-builtin
|
||||
CFLAGS-tst-labs.c += -fno-builtin
|
||||
+CFLAGS-tst-llabs.c += -fno-builtin
|
||||
|
||||
ifeq ($(have-cxx-thread_local),yes)
|
||||
CFLAGS-tst-quick_exit.o = -std=c++11
|
||||
diff --git a/stdlib/tst-llabs.c b/stdlib/tst-llabs.c
|
||||
new file mode 100644
|
||||
index 0000000000000000..be3cd78ceb5e8013
|
||||
--- /dev/null
|
||||
+++ b/stdlib/tst-llabs.c
|
||||
@@ -0,0 +1,55 @@
|
||||
+/* Basic tests for llabs.
|
||||
+ Copyright (C) 2023 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <https://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#include <limits.h>
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+#include <support/check.h>
|
||||
+
|
||||
+#define LARGE_PRIME 49999
|
||||
+
|
||||
+static int do_test (void)
|
||||
+{
|
||||
+ long i;
|
||||
+
|
||||
+ TEST_COMPARE(llabs(LLONG_MAX), LLONG_MAX);
|
||||
+ TEST_COMPARE(llabs(LLONG_MIN + 1), LLONG_MAX);
|
||||
+ TEST_COMPARE(llabs(0x00000000ffffffffL), 0x00000000ffffffffL);
|
||||
+ TEST_COMPARE(llabs(0x0000000100000000L), 0x0000000100000000L);
|
||||
+ TEST_COMPARE(llabs(0x80000000ffffffffL), 0x7fffffff00000001L);
|
||||
+ TEST_COMPARE(llabs(0x8000000100000000L), 0x7fffffff00000000L);
|
||||
+ TEST_COMPARE(llabs(-1), 1);
|
||||
+ TEST_COMPARE(llabs(0), 0);
|
||||
+ TEST_COMPARE(llabs(1), 1);
|
||||
+
|
||||
+ for (i = LLONG_MIN + 1; i < LLONG_MIN + INT_MAX; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(llabs(i), -i);
|
||||
+
|
||||
+ for (i = LLONG_MAX - INT_MAX; i < LLONG_MAX - LARGE_PRIME; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(llabs(i), i);
|
||||
+
|
||||
+ for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(llabs(i), -i);
|
||||
+
|
||||
+ for (i = 0; i < INT_MAX; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE(llabs(i), i);
|
||||
+
|
||||
+ return EXIT_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+#include <support/test-driver.c>
|
||||
59
glibc-RHEL-77082-4.patch
Normal file
59
glibc-RHEL-77082-4.patch
Normal file
@ -0,0 +1,59 @@
|
||||
commit 8812b9900e5fba3b696f1b34bd6014211327190f
|
||||
Author: Florian Weimer <fweimer@redhat.com>
|
||||
Date: Tue May 16 22:54:25 2023 +0200
|
||||
|
||||
stdlib: Use long long int in stdlib/tst-llabs
|
||||
|
||||
And adjust for GNU style.
|
||||
|
||||
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
||||
|
||||
diff --git a/stdlib/tst-llabs.c b/stdlib/tst-llabs.c
|
||||
index be3cd78ceb5e8013..5e4d52def9719201 100644
|
||||
--- a/stdlib/tst-llabs.c
|
||||
+++ b/stdlib/tst-llabs.c
|
||||
@@ -25,29 +25,29 @@
|
||||
|
||||
static int do_test (void)
|
||||
{
|
||||
- long i;
|
||||
-
|
||||
- TEST_COMPARE(llabs(LLONG_MAX), LLONG_MAX);
|
||||
- TEST_COMPARE(llabs(LLONG_MIN + 1), LLONG_MAX);
|
||||
- TEST_COMPARE(llabs(0x00000000ffffffffL), 0x00000000ffffffffL);
|
||||
- TEST_COMPARE(llabs(0x0000000100000000L), 0x0000000100000000L);
|
||||
- TEST_COMPARE(llabs(0x80000000ffffffffL), 0x7fffffff00000001L);
|
||||
- TEST_COMPARE(llabs(0x8000000100000000L), 0x7fffffff00000000L);
|
||||
- TEST_COMPARE(llabs(-1), 1);
|
||||
- TEST_COMPARE(llabs(0), 0);
|
||||
- TEST_COMPARE(llabs(1), 1);
|
||||
+ long long int i;
|
||||
+
|
||||
+ TEST_COMPARE (llabs (LLONG_MAX), LLONG_MAX);
|
||||
+ TEST_COMPARE (llabs (LLONG_MIN + 1), LLONG_MAX);
|
||||
+ TEST_COMPARE (llabs (0x00000000ffffffffL), 0x00000000ffffffffL);
|
||||
+ TEST_COMPARE (llabs (0x0000000100000000L), 0x0000000100000000L);
|
||||
+ TEST_COMPARE (llabs (0x80000000ffffffffL), 0x7fffffff00000001L);
|
||||
+ TEST_COMPARE (llabs (0x8000000100000000L), 0x7fffffff00000000L);
|
||||
+ TEST_COMPARE (llabs (-1), 1);
|
||||
+ TEST_COMPARE (llabs (0), 0);
|
||||
+ TEST_COMPARE (llabs (1), 1);
|
||||
|
||||
for (i = LLONG_MIN + 1; i < LLONG_MIN + INT_MAX; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(llabs(i), -i);
|
||||
+ TEST_COMPARE (llabs (i), -i);
|
||||
|
||||
for (i = LLONG_MAX - INT_MAX; i < LLONG_MAX - LARGE_PRIME; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(llabs(i), i);
|
||||
+ TEST_COMPARE (llabs (i), i);
|
||||
|
||||
for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(llabs(i), -i);
|
||||
+ TEST_COMPARE (llabs (i), -i);
|
||||
|
||||
for (i = 0; i < INT_MAX; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(llabs(i), i);
|
||||
+ TEST_COMPARE (llabs (i), i);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
56
glibc-RHEL-77082-5.patch
Normal file
56
glibc-RHEL-77082-5.patch
Normal file
@ -0,0 +1,56 @@
|
||||
commit 10a81dd4cf89276f7b1208ed044b93ae846800ce
|
||||
Author: Florian Weimer <fweimer@redhat.com>
|
||||
Date: Tue May 16 23:26:40 2023 +0200
|
||||
|
||||
stdlib: Avoid undefined behavior in stdlib/tst-labs
|
||||
|
||||
The last loop could attempt to overflow beyond INT_MAX on 32-bit
|
||||
architectures.
|
||||
|
||||
Also switch to GNU style.
|
||||
|
||||
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
||||
|
||||
diff --git a/stdlib/tst-labs.c b/stdlib/tst-labs.c
|
||||
index 92b456745ac1bb2d..a8d2381f87bca855 100644
|
||||
--- a/stdlib/tst-labs.c
|
||||
+++ b/stdlib/tst-labs.c
|
||||
@@ -25,25 +25,26 @@
|
||||
|
||||
static int do_test (void)
|
||||
{
|
||||
- long i;
|
||||
+ long int i;
|
||||
|
||||
- TEST_COMPARE(labs(LONG_MAX), LONG_MAX);
|
||||
- TEST_COMPARE(labs(LONG_MIN + 1), LONG_MAX);
|
||||
- TEST_COMPARE(labs(-1), 1);
|
||||
- TEST_COMPARE(labs(0), 0);
|
||||
- TEST_COMPARE(labs(1), 1);
|
||||
+ TEST_COMPARE (labs (LONG_MAX), LONG_MAX);
|
||||
+ TEST_COMPARE (labs (LONG_MIN + 1), LONG_MAX);
|
||||
+ TEST_COMPARE (labs (-1), 1);
|
||||
+ TEST_COMPARE (labs (0), 0);
|
||||
+ TEST_COMPARE (labs (1), 1);
|
||||
|
||||
for (i = LONG_MIN + 1; i < LONG_MIN + INT_MAX; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(labs(i), -i);
|
||||
+ TEST_COMPARE (labs (i), -i);
|
||||
|
||||
- for (i = LONG_MAX - INT_MAX; i < LONG_MAX - LARGE_PRIME; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(labs(i), i);
|
||||
+ for (i = LONG_MAX - INT_MAX; i < LONG_MAX - LARGE_PRIME;
|
||||
+ i += LARGE_PRIME)
|
||||
+ TEST_COMPARE (labs (i), i);
|
||||
|
||||
for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(labs(i), -i);
|
||||
+ TEST_COMPARE (labs (i), -i);
|
||||
|
||||
- for (i = 0; i < INT_MAX; i += LARGE_PRIME)
|
||||
- TEST_COMPARE(labs(i), i);
|
||||
+ for (i = 0; i <= INT_MAX - LARGE_PRIME; i += LARGE_PRIME)
|
||||
+ TEST_COMPARE (labs (i), i);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
10
glibc.spec
10
glibc.spec
@ -157,7 +157,7 @@ end \
|
||||
Summary: The GNU libc libraries
|
||||
Name: glibc
|
||||
Version: %{glibcversion}
|
||||
Release: 204%{?dist}
|
||||
Release: 205%{?dist}
|
||||
|
||||
# In general, GPLv2+ is used by programs, LGPLv2+ is used for
|
||||
# libraries.
|
||||
@ -1237,6 +1237,11 @@ Patch928: glibc-RHEL-57110-2.patch
|
||||
Patch929: glibc-RHEL-57110-3.patch
|
||||
Patch930: glibc-RHEL-57110-4.patch
|
||||
Patch931: glibc-RHEL-57110-5.patch
|
||||
Patch932: glibc-RHEL-77082-1.patch
|
||||
Patch933: glibc-RHEL-77082-2.patch
|
||||
Patch934: glibc-RHEL-77082-3.patch
|
||||
Patch935: glibc-RHEL-77082-4.patch
|
||||
Patch936: glibc-RHEL-77082-5.patch
|
||||
|
||||
##############################################################################
|
||||
# Continued list of core "glibc" package information:
|
||||
@ -3230,6 +3235,9 @@ update_gconv_modules_cache ()
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Wed Jun 11 2025 Frédéric Bérat <fberat@redhat.com> - 2.34-205
|
||||
- Add testcases for abs(), labs(), and llabs() functions. (RHEL-77082)
|
||||
|
||||
* Wed Jun 11 2025 Arjun Shankar <arjun@redhat.com> - 2.34-204
|
||||
- manual: Document error codes of several socket functions (RHEL-57110)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user