Paul Eggert wrote in <https://lists.gnu.org/archive/html/bug-gnulib/2024-08/msg00088.html>: > Also m4 still has a bogus -Wnull-dereference diagnostic, unrelated to the > verror.h changes, that somebody needs to investigate when they find the time.
The warning can be seen with gcc 14.1 or 14.2. How to reproduce: $ ./configure --enable-gcc-warnings $ make V=1 The result with gcc 14.x: gcc -I../lib -I../lib -fanalyzer -fstrict-flex-arrays -Wall -Warith-conversion -Wbad-function-cast -Wcast-align=strict -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wextra -Wformat-signedness -Wflex-array-member-not-at-end -Winit-self -Winline -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-variable-declarations -Wnested-externs -Wnull-dereference -Wold-style-definition -Wopenmp-simd -Woverlength-strings -Wpacked -Wpointer-arith -Wshadow -Wstack-protector -Wstrict-flex-arrays -Wstrict-overflow -Wstrict-prototypes -Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wtrampolines -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunused-macros -Wvariadic-macros -Wvector-operation-performance -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wbidi-chars=any,ucn -Wformat-overflow=2 -Wformat=2 -Wformat-truncation=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 -Wuse-after-free=3 -Wunused-const-variable=2 -Wvla-larger-than=4031 -Wno-analyzer-malloc-leak -g -O2 -c output.c output.c: In function 'make_room_for': output.c:491:40: warning: potential null pointer dereference [-Wnull-dereference] 491 | output_file = output_diversion->u.file; | ~~~~~~~~~~~~~~~~~~~^~~~~ I submitted this as a GCC bug: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116426> A consequence of this warning is that with --enable-gcc-warnings, all gcc versions from 11 to 14 produce warnings on glibc systems: gcc 11.5.0: error: function might be candidate for attribute 'cold' gcc 12.4.0: error: function might be candidate for attribute 'cold' gcc 13.3.0: error: function might be candidate for attribute 'cold' error: potential null pointer dereference gcc 14.2.0: error: potential null pointer dereference Reminder about the other warning: CC macro.o In function 'call_macro.part.0': ../../../src/macro.c:272:1: error: function might be candidate for attribute 'cold' [-Werror=suggest-attribute=cold] 272 | call_macro (symbol *sym, int argc, token_data **argv, | ^~~~~~~~~~ Which is a bogus warning as well. I cannot find it reported in the GCC bug tracker. But at least, it's fixed in GCC 14. What can we do about it? I don't find it adequate to change the logic of the function 'make_room_for'. Usually we - disable a warning option completely if it generates nearly only false alarms, - disable a warning option for a certain compilation unit, to work around specific false alarms. Here we are in the second case. Here's a proposed patch.
>From d891c52c1ca8ffae0aa9cebea572dccba1186355 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 20 Aug 2024 03:27:43 +0200 Subject: [PATCH] maint: Avoid a gcc 14 warning that makes --enable-gcc-warnings break. * src/output.c: Disable -Wnull-dereference warnings in this file. --- src/output.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/output.c b/src/output.c index 6dc8280a..65f183dd 100644 --- a/src/output.c +++ b/src/output.c @@ -27,6 +27,12 @@ #include "gl_avltree_oset.h" #include "gl_xoset.h" +/* Work around a bogus GCC warning + <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116426>. */ +#if __GNUC__ >= 6 +# pragma GCC diagnostic ignored "-Wnull-dereference" +#endif + /* Size of initial in-memory buffer size for diversions. Small diversions would usually fit in. */ #define INITIAL_BUFFER_SIZE 512 -- 2.34.1