Fix definition of ossl_intmax_t and ossl_uintmax_t
authorRichard Levitte <levitte@openssl.org>
Fri, 18 Jun 2021 08:32:32 +0000 (10:32 +0200)
committerPauli <pauli@openssl.org>
Tue, 22 Jun 2021 09:49:52 +0000 (19:49 +1000)
These definitions were located away from our definitions of other
sized int and uint types.  Also, the fallback typedef wasn't quite
correct, and this changes it to be aliases for int64_t and uint64_t,
since those are the largest integers we commonly handle.

We also make sure to define corresponding numbers: OSSL_INTMAX_MIN,
OSSL_INTMAX_MAX and OSSL_UINTMAX_MAX

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15825)

include/internal/numbers.h
include/openssl/e_os2.h
include/openssl/types.h

index ac801364d919291008e92f37418f419ddeb3a8dc..4f4d3306d5da80dfb21ef4e9b5fb2fc9598b4bec 100644 (file)
@@ -75,5 +75,11 @@ typedef __uint128_t uint128_t;
 #  define SIZE_MAX __MAXUINT__(size_t)
 # endif
 
+# ifndef OSSL_INTMAX_MAX
+#  define OSSL_INTMAX_MIN __MININT__(ossl_intmax_t)
+#  define OSSL_INTMAX_MAX __MAXINT__(ossl_intmax_t)
+#  define OSSL_UINTMAX_MAX __MAXUINT__(ossl_uintmax_t)
+# endif
+
 #endif
 
index 49e6dad73c20434675d139a15acbf97eb303836e..67289092717a02685c1fa2b73c03fdc87e946a17 100644 (file)
@@ -252,6 +252,15 @@ typedef unsigned __int64 uint64_t;
 #  include <stdint.h>
 #  undef OPENSSL_NO_STDINT_H
 # endif
+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
+    defined(INTMAX_MAX) && defined(UINTMAX_MAX)
+typedef intmax_t ossl_intmax_t;
+typedef uintmax_t ossl_uintmax_t;
+# else
+/* Fall back to the largest we know we require and can handle */
+typedef int64_t ossl_intmax_t;
+typedef uint64_t ossl_uintmax_t;
+# endif
 
 /* ossl_inline: portable inline definition usable in public headers */
 # if !defined(inline) && !defined(__cplusplus)
index bf5846db054a45cebe98ccc8de335de06a5288ee..de9f1665249f5db05a90ffe8550ee863d72b1f40 100644 (file)
@@ -229,21 +229,6 @@ typedef struct ossl_decoder_ctx_st OSSL_DECODER_CTX;
 
 typedef struct ossl_self_test_st OSSL_SELF_TEST;
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
-    defined(INTMAX_MAX) && defined(UINTMAX_MAX)
-typedef intmax_t ossl_intmax_t;
-typedef uintmax_t ossl_uintmax_t;
-#else
-/*
- * Not long long, because the C-library can only be expected to provide
- * strtoll(), strtoull() at the same time as intmax_t and strtoimax(),
- * strtoumax().  Since we use these for parsing arguments, we need the
- * conversion functions, not just the sizes.
- */
-typedef long ossl_intmax_t;
-typedef unsigned long ossl_uintmax_t;
-#endif
-
 #ifdef  __cplusplus
 }
 #endif