diff --git a/crypto/test/file_test.h b/crypto/test/file_test.h index 24651ab85..8fb7ed22b 100644 --- a/crypto/test/file_test.h +++ b/crypto/test/file_test.h @@ -15,6 +15,8 @@ #ifndef OPENSSL_HEADER_CRYPTO_TEST_FILE_TEST_H #define OPENSSL_HEADER_CRYPTO_TEST_FILE_TEST_H +#include + #include #include @@ -88,11 +90,7 @@ class FileTest { // PrintLine is a variant of printf which prepends the line number and appends // a trailing newline. - void PrintLine(const char *format, ...) -#ifdef __GNUC__ - __attribute__((__format__(__printf__, 2, 3))) -#endif - ; + void PrintLine(const char *format, ...) OPENSSL_PRINTF_FORMAT_FUNC(2, 3); unsigned start_line() const { return start_line_; } diff --git a/include/openssl/base.h b/include/openssl/base.h index 47b3ccb99..65ab3f776 100644 --- a/include/openssl/base.h +++ b/include/openssl/base.h @@ -138,6 +138,15 @@ extern "C" { #endif /* defined(BORINGSSL_SHARED_LIBRARY) */ + +#if defined(__GNUC__) +#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \ + __attribute__((format(printf, string_index, first_to_check))) +#else +#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) +#endif + + /* CRYPTO_THREADID is a dummy value. */ typedef int CRYPTO_THREADID; diff --git a/include/openssl/bio.h b/include/openssl/bio.h index c88a3e187..0c8bfe405 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -312,14 +312,8 @@ OPENSSL_EXPORT void BIO_copy_next_retry(BIO *bio); * * These functions are versions of printf functions that output to a BIO rather * than a FILE. */ -#ifdef __GNUC__ -#define __bio_h__attr__ __attribute__ -#else -#define __bio_h__attr__(x) -#endif OPENSSL_EXPORT int BIO_printf(BIO *bio, const char *format, ...) - __bio_h__attr__((__format__(__printf__, 2, 3))); -#undef __bio_h__attr__ + OPENSSL_PRINTF_FORMAT_FUNC(2, 3); /* Utility functions. */ diff --git a/include/openssl/mem.h b/include/openssl/mem.h index c8e2b3ef0..46d75d12b 100644 --- a/include/openssl/mem.h +++ b/include/openssl/mem.h @@ -119,18 +119,12 @@ OPENSSL_EXPORT int OPENSSL_strncasecmp(const char *a, const char *b, size_t n); * These functions are either OpenSSL wrappers for standard functions (i.e. * |BIO_snprintf| and |BIO_vsnprintf|) which don't exist in C89, or are * versions of printf functions that output to a BIO rather than a FILE. */ -#ifdef __GNUC__ -#define __bio_h__attr__ __attribute__ -#else -#define __bio_h__attr__(x) -#endif OPENSSL_EXPORT int BIO_snprintf(char *buf, size_t n, const char *format, ...) - __bio_h__attr__((__format__(__printf__, 3, 4))); + OPENSSL_PRINTF_FORMAT_FUNC(3, 4); OPENSSL_EXPORT int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) - __bio_h__attr__((__format__(__printf__, 3, 0))); -#undef __bio_h__attr__ + OPENSSL_PRINTF_FORMAT_FUNC(3, 0); #if defined(__cplusplus)