From c561aa64b6c42192806fb9f74d8ffafa2ab8d64f Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 9 May 2015 01:38:06 -0400 Subject: [PATCH] Require source files define __STDC_FORMAT_MACROS to use BN FMT macros. inttypes.h kindly requires a feature macro in C++ on some platforms, due to a bizarre footnote in C99 (see footnote 191 in section 7.8.1). As bn.h is a public header, we must leak this wart to the consumer. On platforms with unfriendly inttypes.h headers, using BN_DEC_FMT1 and friends now require the feature macro be defined externally. This broke the Chromium Android Clang builder: http://build.chromium.org/p/chromium.linux/builders/Android%20Clang%20Builder%20%28dbg%29/builds/59288 Change-Id: I88275a6788c7babd0eae32cae86f115bfa93a591 Reviewed-on: https://boringssl-review.googlesource.com/4688 Reviewed-by: Adam Langley --- crypto/bn/bn_test.cc | 6 +++++- crypto/bn/internal.h | 6 ------ include/openssl/bn.h | 7 ++++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc index 3c239d3b..9aa2bf58 100644 --- a/crypto/bn/bn_test.cc +++ b/crypto/bn/bn_test.cc @@ -67,6 +67,11 @@ * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems * Laboratories. */ +/* For BIGNUM format macros. */ +#if !defined(__STDC_FORMAT_MACROS) +#define __STDC_FORMAT_MACROS +#endif + #include #include @@ -76,7 +81,6 @@ #include #include "../crypto/test/scoped_types.h" -#include "internal.h" static const int num0 = 100; // number of tests diff --git a/crypto/bn/internal.h b/crypto/bn/internal.h index ed3416aa..2674b3cd 100644 --- a/crypto/bn/internal.h +++ b/crypto/bn/internal.h @@ -125,12 +125,6 @@ #include -/* Some versions of inttypes.h will not define print macros in C++ unless - * __STDC_FORMAT_MACROS is set. */ -#if !defined(__STDC_FORMAT_MACROS) -#define __STDC_FORMAT_MACROS -#endif - #if defined(OPENSSL_X86_64) && defined(_MSC_VER) && _MSC_VER >= 1400 #pragma warning(push, 3) #include diff --git a/include/openssl/bn.h b/include/openssl/bn.h index 18aba5ff..2cd02245 100644 --- a/include/openssl/bn.h +++ b/include/openssl/bn.h @@ -139,7 +139,12 @@ extern "C" { * will allow you to work with numbers until you run out of memory. */ -/* BN_ULONG is the native word size when working with big integers. */ +/* BN_ULONG is the native word size when working with big integers. + * + * Note: on some platforms, inttypes.h does not define print format macros in + * C++ unless |__STDC_FORMAT_MACROS| defined. As this is a public header, bn.h + * does not define |__STDC_FORMAT_MACROS| itself. C++ source files which use the + * FMT macros must define it externally. */ #if defined(OPENSSL_64_BIT) #define BN_ULONG uint64_t #define BN_BITS2 64