]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
tasn_dec: use do/while around statement macros
authorBenjamin Kaduk <bkaduk@akamai.com>
Tue, 4 May 2021 19:33:28 +0000 (12:33 -0700)
committerBenjamin Kaduk <bkaduk@akamai.com>
Sat, 8 May 2021 16:22:36 +0000 (09:22 -0700)
Use the do {} while (0) construct around macros whose bodies are complete
statements (including one that has internal control flow!).  This is
safer and avoids any risk of misinterpretation if the macro is used in
an unexpected context.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15143)

crypto/asn1/tasn_dec.c

index 20717df461d2c0e8298f1382d26cfccaf4701d75..aaf3de7e192bc4187cd3158286c439c09c7ec16a 100644 (file)
@@ -90,9 +90,9 @@ unsigned long ASN1_tag2bit(int tag)
 
 /* Macro to initialize and invalidate the cache */
 
-#define asn1_tlc_clear(c)       if ((c) != NULL) (c)->valid = 0
+#define asn1_tlc_clear(c)       do { if ((c) != NULL) (c)->valid = 0; } while (0)
 /* Version to avoid compiler warning about 'c' always non-NULL */
-#define asn1_tlc_clear_nc(c)    (c)->valid = 0
+#define asn1_tlc_clear_nc(c)    do {(c)->valid = 0; } while (0)
 
 /*
  * Decode an ASN1 item, this currently behaves just like a standard 'd2i'