]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 14:00:15 +0000 (15:00 +0100)
committerAlejandro Colomar <alx@kernel.org>
Mon, 27 May 2024 14:32:09 +0000 (16:32 +0200)
All call sites have been replaced by functions from "atoi/a2i.h" and
"atoi/str2i.h" recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/atoi/strtou_noneg.c
lib/atoi/strtou_noneg.h
tests/unit/Makefile.am
tests/unit/test_atoi_strtou_noneg.c [deleted file]

index 96a0b530e24726192751fbbf98eb43a79631fe1c..71cacbd1e85fe3fe258f46430f0529829c63e6d1 100644 (file)
@@ -11,6 +11,3 @@
 
 extern inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
     int base, uintmax_t min, uintmax_t max, int *restrict status);
-
-extern inline unsigned long strtoul_noneg(const char *s,
-    char **restrict endp, int base);
index c9411d0ea222211cb492862c5604b79c3d7b5f93..6d77adf5ecd76ffb4d311f3f4c990e0b526b8209 100644 (file)
@@ -9,8 +9,8 @@
 #include <config.h>
 
 #include <errno.h>
+#include <stddef.h>
 #include <stdint.h>
-#include <stdlib.h>
 
 #include "atoi/strtoi.h"
 #include "attr.h"
@@ -20,10 +20,6 @@ ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
 inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
     int base, uintmax_t min, uintmax_t max, int *restrict status);
 
-ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
-inline unsigned long strtoul_noneg(const char *s,
-    char **restrict endp, int base);
-
 
 inline uintmax_t
 strtou_noneg(const char *s, char **restrict endp, int base,
@@ -40,15 +36,4 @@ strtou_noneg(const char *s, char **restrict endp, int base,
 }
 
 
-inline unsigned long
-strtoul_noneg(const char *s, char **restrict endp, int base)
-{
-       if (strtol(s, endp, base) < 0) {
-               errno = ERANGE;
-               return 0;
-       }
-       return strtoul(s, endp, base);
-}
-
-
 #endif  // include guard
index 228d879618bc686d4a1b2256dd1c2857c1c62219..d89367a3702f23a8dd4bcdaba80beb93c72651f2 100644 (file)
@@ -6,7 +6,6 @@ TESTS = $(check_PROGRAMS)
 check_PROGRAMS = \
     test_adds \
     test_atoi_strtoi \
-    test_atoi_strtou_noneg \
     test_chkname \
     test_sprintf \
     test_strncpy \
@@ -48,19 +47,6 @@ test_atoi_strtoi_LDADD = \
     $(CMOCKA_LIBS) \
     $(NULL)
 
-test_atoi_strtou_noneg_SOURCES = \
-    ../../lib/atoi/strtou_noneg.c \
-    test_atoi_strtou_noneg.c \
-    $(NULL)
-test_atoi_strtou_noneg_CFLAGS = \
-    $(AM_CFLAGS) \
-    $(NULL)
-test_atoi_strtou_noneg_LDFLAGS = \
-    $(NULL)
-test_atoi_strtou_noneg_LDADD = \
-    $(CMOCKA_LIBS) \
-    $(NULL)
-
 test_chkname_SOURCES = \
     ../../lib/chkname.c \
     test_chkname.c \
diff --git a/tests/unit/test_atoi_strtou_noneg.c b/tests/unit/test_atoi_strtou_noneg.c
deleted file mode 100644 (file)
index 6063121..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
-// SPDX-License-Identifier: BSD-3-Clause
-
-
-#include <errno.h>
-#include <limits.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-#include <stdarg.h>  // Required by <cmocka.h>
-#include <stddef.h>  // Required by <cmocka.h>
-#include <setjmp.h>  // Required by <cmocka.h>
-#include <stdint.h>  // Required by <cmocka.h>
-#include <cmocka.h>
-
-#include "atoi/strtou_noneg.h"
-
-
-static void test_strtoul_noneg(void **state);
-
-
-int
-main(void)
-{
-    const struct CMUnitTest  tests[] = {
-        cmocka_unit_test(test_strtoul_noneg),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
-
-static void
-test_strtoul_noneg(void **state)
-{
-       errno = 0;
-       assert_true(strtoul_noneg("42", NULL, 0) == 42);
-       assert_true(errno == 0);
-
-       assert_true(strtoul_noneg("-1", NULL, 0) == 0);
-       assert_true(errno == ERANGE);
-       errno = 0;
-       assert_true(strtoul_noneg("-3", NULL, 0) == 0);
-       assert_true(errno == ERANGE);
-       errno = 0;
-       assert_true(strtoul_noneg("-0xFFFFFFFFFFFFFFFF", NULL, 0) == 0);
-       assert_true(errno == ERANGE);
-
-       errno = 0;
-       assert_true(strtoul_noneg("-0x10000000000000000", NULL, 0) == 0);
-       assert_true(errno == ERANGE);
-}