From: Neil Horman Date: Tue, 23 Jul 2024 15:34:29 +0000 (-0400) Subject: Fix strtoul test on alpine/musl X-Git-Tag: openssl-3.4.0-alpha1~292 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec1d8ead2855f6cd529f9a1ace0a667f34eefc58;p=thirdparty%2Fopenssl.git Fix strtoul test on alpine/musl The strtoul tests that were recently added had a compile time check for __WORDSIZE to properly determine the string to use for an maximal unsigned long. Unfortunately musl libc doesn't define __WORDSIZE so we were in a position where on that platform we fall to the 32 bit unsigned long variant, which breaks on x86 platforms. Fix it by doing a preprocessor comparisong on ULONG_MAX instead. NOTE: This works because preprocessors do arithmetic evaluation on macros for every compiler we support. We should be wary of some more esoteric compilers though. Reviewed-by: Matt Caswell Reviewed-by: Tom Cosgrove (Merged from https://github.com/openssl/openssl/pull/24974) --- diff --git a/test/strtoultest.c b/test/strtoultest.c index 267cdf114c3..f766b9d433f 100644 --- a/test/strtoultest.c +++ b/test/strtoultest.c @@ -36,16 +36,17 @@ static struct strtoul_test_entry strtoul_tests[] = { { "0x12345", 10, 0, 1, 1 }, -#if defined(__WORDSIZE) && __WORDSIZE == 64 +#if ULONG_MAX == 4294967295 /* pass on ULONG_MAX translation */ { - "18446744073709551615", 0, ULONG_MAX, 1, 20 + "4294967295", 0, ULONG_MAX, 1, 10 }, #else { - "4294967295", 0, ULONG_MAX, 1, 10 + "18446744073709551615", 0, ULONG_MAX, 1, 20 }, #endif + /* fail on negative input */ { "-1", 0, 0, 0, 0