fix warning with gcc 12.2.0 (compiler bug?)
RFC PATCH 1/1 fix warning with gcc 12.2.0 (compiler bug?)
Changing the argument of check_malloc_return from const void* to void* removes the warning from gcc 12.2.0:
In file included from ../../../openvpn-git/src/openvpn/crypto_openssl.c:40:../../../openvpn-git/src/openvpn/buffer.h: In function ‘hmac_ctx_new’:../../../openvpn-git/src/openvpn/buffer.h:1030:9: warning: ‘ctx’ may be used uninitialized [-Wmaybe-uninitialized]
1030 | check_malloc_return((dptr) = (type *) malloc(sizeof(type))); \
| ^~~~~~~~~~~~~~~~~~~
../../../openvpn-git/src/openvpn/buffer.h:1076:1: note: by argument 1 of type ‘const void *’ to ‘check_malloc_return’ declared here
1076 | check_malloc_return(const void *p)
| ^~~~~~~~~~~~~~~~~~~This more a quick fix/heads up for other people encountering the issue on GCC 12.2.0 like on Ubuntu 22.10 until we figure out if this is a bug in our code or a compiler bug.
--- src/openvpn/buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/buffer.h +1 -1
@@ -1073,7 +1073,7 @@ gc_reset(struct gc_arena *a) }static inline void -check_malloc_return (const void *p) +check_malloc_return (void *p) {if (!p) {
Signature · 1 line
2.37.1 (Apple Git-137.1)
Quoted 26 lines · Arne Schwabe
Changing the argument of
check_malloc_returnfrom const void* to void* removes the warning from gcc 12.2.0:In file included from
../../../openvpn-git/src/openvpn/crypto_openssl.c:40:../../../openvpn-git/src/openvpn/buffer.h: In function ‘hmac_ctx_new’:../../../openvpn-git/src/openvpn/buffer.h:1030:9: warning: ‘ctx’ may be used uninitialized [-Wmaybe-uninitialized]1030 | check_malloc_return((dptr) = (type *) malloc(sizeof(type))); \ | ^~~~~~~~~~~~~~~~~~~ ../../../openvpn-git/src/openvpn/buffer.h:1076:1: note: by argument 1 of type ‘const void *’ to ‘check_malloc_return’ declared here 1076 | check_malloc_return(const void *p) | ^~~~~~~~~~~~~~~~~~~This more a quick fix/heads up for other people encountering the issue on GCC 12.2.0 like on Ubuntu 22.10 until we figure out if this is a bug in our code or a compiler bug.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/openvpn/buffer.h +0
-0
src/openvpn/buffer.h gc_reset(struct gc_arena *a) · line 1079
Quoted 8 lines
src/openvpn/buffer.h +1
-1@@ -1073,7 +1073,7 @@ gc_reset(struct gc_arena *a) }static inline void -check_malloc_return (const void *p) +check_malloc_return (void *p) {if (!p) {
Seen this with gcc 11.3 on Ubuntu 22.04 as well. It only seems to occur on -O0, probably since check_malloc_return will be inlined otherwise.
I would suggest to go ahead with applying the patch. While I think that in our specific case it is a false-positive, the general assumption "a const pointer to a clearly uninitialized area is not useful" is valid in general. Testing the pointer for NULL like we do is literally the one and only thing you can do with it.
On anything other than -O0 it will make no difference anyway. And removing the const is much less ugly than to add some pragmas for gcc to suppress the warning.
So:
Regards,
Signature · 1 line
Frank Lichtenheld
Quoted 1 line · On Sonntag, 27. November 2022 09:59:33 CEST Arne Schwabe wrote:
Signed-off-by Arne Schwabe <[email protected]...>
This one is ugly, but required to build with cmake and mingw with -Werror
Cheers, Heiko
Since the patch is so straightforward, and has an ACK, not tested anything.
Your patch has been applied to the master and release/2.6 branch.
commit 5ad793e8cab8fcccae93fe9442eca6a6de8c044c (master) commit 5bdeda19e7aaa89523180e46369fc85ba204f70f (release/2.6)
Author: Arne Schwabe Date: Sun Nov 27 09:59:33 2022 +0100
fix warning with gcc 12.2.0 (compiler bug?)
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Heiko Hund <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25549.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering