https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102867
Bug ID: 102867
Summary: Waddress complaint in readelf.c
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: amodra at gmail dot com
Target Milestone: ---
Compiling the attached readelf.i with -Wall -Werror -O2 using today's gcc
mainline on x86_64-linux results in complaints like
/home/alan/src/binutils-gdb/binutils/readelf.c: In function ‘find_section’:
/home/alan/src/binutils-gdb/binutils/readelf.c:762:42: error: the comparison
will always evaluate as ‘true’ for the pointer operand in
‘filedata->section_headers + (sizetype)((long unsigned int)i * 80)’ must not be
NULL [-Werror=address]
762 | if (SECTION_NAME_VALID (filedata->section_headers + i)
The warning is true, but annoying when coming from a macro expansion
#define SECTION_NAME_VALID(X) \
((X) != NULL \
&& filedata->string_table != NULL \
&& (X)->sh_name < filedata->string_table_length)
In current readelf.c it looks like it may be possible to remove "(X) != NULL"
from this macro, but that doesn't seem like a good solution. Another macro
with similar complaints
#define SECTION_NAME_PRINT(X) \
((X) == NULL ? _("<none>") \
: filedata->string_table == NULL ? _("<no-strings>") \
: (X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
: filedata->string_table + (X)->sh_name)
can be called with X NULL.