Define |OPENSSL_PRINTF_FORMAT_FUNC| for format string annotations. This centralizes the conditional logic into openssl/base.h so that it doesn't have to be repeated. The name |OPENSSL_PRINTF_FORMAT_FUNC| was chosen in anticipation of eventually defining an |OPENSSL_PRINTF_FORMAT_ARG| for MSVC-style parameter annotations. Change-Id: I273e6eddd209e696dc9f82099008c35b6d477cdb Reviewed-on: https://boringssl-review.googlesource.com/6909 Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/crypto/test/file_test.h b/crypto/test/file_test.h index 24651ab..8fb7ed2 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 <openssl/base.h> + #include <stdint.h> #include <stdio.h> @@ -88,11 +90,7 @@ // 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 47b3ccb..65ab3f7 100644 --- a/include/openssl/base.h +++ b/include/openssl/base.h
@@ -138,6 +138,15 @@ #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 c88a3e1..0c8bfe4 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h
@@ -312,14 +312,8 @@ * * 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 c8e2b3e..46d75d1 100644 --- a/include/openssl/mem.h +++ b/include/openssl/mem.h
@@ -119,18 +119,12 @@ * 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)