From ec87a649dd2128bde780f6e34a4833d9469f6b4d Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 16 Sep 2019 16:23:25 +0200 Subject: [PATCH] include/openssl/macros.h: Rework OPENSSL_FUNC for div C standards OPENSSL_FUNC was defined as an alias for __FUNCTION__ with new enough GNU C, regardless of the language standard used. We change this slightly, so this won't happen unless __STDC_VERSION is defined. Fixes #9911 Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/9913) --- include/openssl/macros.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/include/openssl/macros.h b/include/openssl/macros.h index da5d155680..a06b869522 100644 --- a/include/openssl/macros.h +++ b/include/openssl/macros.h @@ -131,15 +131,31 @@ # endif # endif +/* + * __func__ was standardized in C99, so for any compiler that claims + * to implement that language level or newer, we assume we can safely + * use that symbol. + * + * GNU C also provides __FUNCTION__ since version 2, which predates + * C99. We can, however, only use this if __STDC_VERSION__ exists, + * as it's otherwise not allowed according to ISO C standards (C90). + * (compiling with GNU C's -pedantic tells us so) + * + * If none of the above applies, we check if the compiler is MSVC, + * and use __FUNCTION__ if that's the case. + * + * If all these possibilities are exhausted, we give up and use a + * static string. + */ # ifndef OPENSSL_FUNC -# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -# define OPENSSL_FUNC __func__ -# elif defined(__STRICT_ANSI__) -# define OPENSSL_FUNC "(unknown function)" -# elif defined(_MSC_VER) || (defined(__GNUC__) && __GNUC__ >= 2) -# define OPENSSL_FUNC __FUNCTION__ -# elif defined(__FUNCSIG__) -# define OPENSSL_FUNC __FUNCSIG__ +# if defined(__STDC_VERSION__) +# if __STDC_VERSION__ >= 199901L +# define OPENSSL_FUNC __func__ +# elif defined(__GNUC__) && __GNUC__ >= 2 +# define OPENSSL_FUNC __FUNCTION__ +# endif +# elif defined(_MSC_VER) +# define OPENSSL_FUNC __FUNCTION__ # else # define OPENSSL_FUNC "(unknown function)" # endif -- 2.34.1