From: Amaury Denoyelle Date: Tue, 18 May 2021 09:33:57 +0000 (+0200) Subject: BUILD: ist: prevent gcc11 maybe-uninitialized warning on istalloc X-Git-Tag: v2.5-dev8~182 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a8aff26881c58061d6ca98d3c3e5fc70060c8f4;p=thirdparty%2Fhaproxy.git BUILD: ist: prevent gcc11 maybe-uninitialized warning on istalloc A new warning is reported by gcc11 when using a pointer to uninitialized memory block for a function with a const pointer argument. The warning is triggered for istalloc, used by http_client.c / proxy.c / tcpcheck.c. This warning is reported because the uninitialized memory block allocated by malloc should not be passed to a const argument as in ist2. See https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Warning-Options.html#index-Wmaybe-uninitialized This should be backported up to 2.2. --- diff --git a/include/import/ist.h b/include/import/ist.h index 0dc3008f5c..539a27d261 100644 --- a/include/import/ist.h +++ b/include/import/ist.h @@ -862,7 +862,15 @@ static inline int istissame(const struct ist ist1, const struct ist ist2) */ static inline struct ist istalloc(const size_t size) { - return ist2(malloc(size), 0); + /* Note: do not use ist2 here, as it triggers a gcc11 warning. + * ‘’ may be used uninitialized [-Werror=maybe-uninitialized] + * + * This warning is reported because the uninitialized memory block + * allocated by malloc should not be passed to a const argument as in + * ist2. + * See https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Warning-Options.html#index-Wmaybe-uninitialized + */ + return (struct ist){ .ptr = malloc(size), .len = 0 }; } /* This function performs the equivalent of free() on the given .