diff options
author | Pauli <pauli@openssl.org> | 2021-06-19 09:54:55 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-07-06 18:42:12 +1000 |
commit | ef1e0242a9aec5210845df86162c0b9219ff0f11 (patch) | |
tree | 1606ff65a95d8940e5f09c18ee1fc5ebf62dc74a /test/sanitytest.c | |
parent | 4e20d04ee0e7be2061c1e5d2c2c8d714b7923c89 (diff) | |
download | openssl-ef1e0242a9aec5210845df86162c0b9219ff0f11.tar.gz |
test: add some integral type size sanity checks
With the recent problem on VMS of maxint_t being defined as a 32 bit integer
despite OpenSSL mandating 64 bit integers being available, it seems prudent
to add some sanity checks for out integral types.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15830)
Diffstat (limited to 'test/sanitytest.c')
-rw-r--r-- | test/sanitytest.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/test/sanitytest.c b/test/sanitytest.c index 46cd224e7a..892b3b55e1 100644 --- a/test/sanitytest.c +++ b/test/sanitytest.c @@ -8,6 +8,7 @@ */ #include <string.h> +#include <openssl/types.h> #include "testutil.h" #include "internal/numbers.h" @@ -76,6 +77,38 @@ static int test_sanity_unsigned_conversion(void) static int test_sanity_range(void) { + /* Verify some types are the correct size */ + if (!TEST_size_t_eq(sizeof(int8_t), 1) + || !TEST_size_t_eq(sizeof(uint8_t), 1) + || !TEST_size_t_eq(sizeof(int16_t), 2) + || !TEST_size_t_eq(sizeof(uint16_t), 2) + || !TEST_size_t_eq(sizeof(int32_t), 4) + || !TEST_size_t_eq(sizeof(uint32_t), 4) + || !TEST_size_t_eq(sizeof(int64_t), 8) + || !TEST_size_t_eq(sizeof(uint64_t), 8) +#ifdef UINT128_MAX + || !TEST_size_t_eq(sizeof(int128_t), 16) + || !TEST_size_t_eq(sizeof(uint128_t), 16) +#endif + || !TEST_size_t_eq(sizeof(char), 1) + || !TEST_size_t_eq(sizeof(unsigned char), 1)) + return 0; + + /* We want our long longs to be at least 64 bits */ + if (!TEST_size_t_ge(sizeof(long long int), 8) + || !TEST_size_t_ge(sizeof(unsigned long long int), 8)) + return 0; + + /* + * Verify intmax_t. + * Some platforms defined intmax_t to be 64 bits but still support + * an int128_t, so this check is for at least 64 bits. + */ + if (!TEST_size_t_ge(sizeof(ossl_intmax_t), 8) + || !TEST_size_t_ge(sizeof(ossl_uintmax_t), 8) + || !TEST_size_t_ge(sizeof(ossl_uintmax_t), sizeof(size_t))) + return 0; + /* This isn't possible to check using the framework functions */ if (SIZE_MAX < INT_MAX) { TEST_error("int must not be wider than size_t"); @@ -86,7 +119,7 @@ static int test_sanity_range(void) static int test_sanity_memcmp(void) { - return CRYPTO_memcmp("ab","cd",2); + return CRYPTO_memcmp("ab", "cd", 2); } int setup_tests(void) |