diff --git a/lib/atoi/strtou_noneg.c b/lib/atoi/strtou_noneg.c index 96a0b530e2..71cacbd1e8 100644 --- a/lib/atoi/strtou_noneg.c +++ b/lib/atoi/strtou_noneg.c @@ -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); diff --git a/lib/atoi/strtou_noneg.h b/lib/atoi/strtou_noneg.h index c9411d0ea2..6d77adf5ec 100644 --- a/lib/atoi/strtou_noneg.h +++ b/lib/atoi/strtou_noneg.h @@ -9,8 +9,8 @@ #include #include +#include #include -#include #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 diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index ff882b8d48..3153538dc6 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -6,7 +6,6 @@ TESTS = $(check_PROGRAMS) check_PROGRAMS = \ test_adds \ test_atoi_strtoi \ - test_atoi_strtou_noneg \ test_chkname \ test_sprintf \ test_strncpy \ @@ -47,19 +46,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 index 60631210db..0000000000 --- a/tests/unit/test_atoi_strtou_noneg.c +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar -// SPDX-License-Identifier: BSD-3-Clause - - -#include -#include -#include -#include - -#include // Required by -#include // Required by -#include // Required by -#include // Required by -#include - -#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); -}