Checking __STDC_VERSION__ rather than __STRICT_ANSI__
authorRichard Levitte <levitte@openssl.org>
Mon, 12 Sep 2022 15:29:53 +0000 (17:29 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 13 Sep 2022 07:34:53 +0000 (09:34 +0200)
`__STRICT_ANSI__` is a gnuish flag macro that indicates if `-ansi`
was given on the command line.  To check the C version, it's better
to check the macro `__STDC_VERSION__`.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/19197)

apps/lib/log.c

index 94a91949eabcaa9a488f2835b9c57b5821086a34..7cf5ad5f893bbd4d7611fa4ca0107b1757dcb5d0 100644 (file)
@@ -56,18 +56,31 @@ static void log_with_prefix(const char *prog, const char *fmt, va_list ap)
     BIO_free(pre);
 }
 
+/*
+ * Unfortunately, C before C99 does not define va_copy, so we must
+ * check if it can be assumed to be present.  We do that with an internal
+ * antifeature macro.
+ * C versions since C94 define __STDC_VERSION__, so it's enough to
+ * check its existence and value.
+ */
+#undef OSSL_NO_C99
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ + 0 < 199900L
+# define OSSL_NO_C99
+#endif
+
 void trace_log_message(int category,
                        const char *prog, int level, const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
-#ifdef __STRICT_ANSI__ /* unfortuantely, ANSI does not define va_copy */
+
+#ifdef OSSL_NO_C99
     if (verbosity >= level)
         category = -1; /* disabling trace output in addition to logging */
 #endif
     if (category >= 0 && OSSL_trace_enabled(category)) {
         BIO *out = OSSL_trace_begin(category);
-#ifndef __STRICT_ANSI__
+#ifndef OSSL_NO_C99
         va_list ap_copy;
 
         va_copy(ap_copy, ap);