public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: elfutils-devel@sourceware.org
Subject: [PATCH] Tests: Fix warning in show-die-info.c
Date: Tue, 5 Oct 2021 17:32:16 +0200	[thread overview]
Message-ID: <20211005153216.fadk42msbpz4xvx5@lug-owl.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 2994 bytes --]

Hi!

I'm running automated test compiles on Binutils, GCC, Linux, NetBSD
and, since a few days ago, elfutils.

Building/running the tests, I noticed this little warning:

.../configure --enable-maintainer-mode --enable-tests-rpath --enable-gprof --enable-gcov --enable-valgrind --prefix=/tmp/elfutils

make make V=1

[make 2021-10-01 12:18:08] /usr/lib/gcc-snapshot/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144   -D_FORTIFY_SOURCE=2 -g -O2 -pg -fprofile-arcs -ftest-coverage -Wl,-rpath-link,../libelf:../libdw -Wno-error=stack-usage= -pg -fprofile-arcs -o strip strip.o ../libebl/libebl.a ../backends/libebl_backends.a ../libcpu/libcpu.a ../libelf/libelf.a -lz ../libdw/libdw.a -lz -lzstd -llzma -lbz2  ../libelf/libelf.a -lz -ldl -lpthread ../lib/libeu.a  
[make 2021-10-01 12:18:08] /usr/lib/gcc-snapshot/bin/gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/tmp/elfutils/share/locale"'  -DDEBUGPRED=0 -DSRCDIR=\"/var/lib/laminar/run/elfutils/11/elfutils/src\" -DOBJDIR=\"/var/lib/laminar/run/elfutils/11/elfutils/src\" -I. -I..  -I. -I. -I../lib -I.. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../libdwfl -I./../libasm  -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra    -D_FORTIFY_SOURCE=2 -g -O2 -pg -fprofile-arcs -ftest-coverage -MT elflint.o -MD -MP -MF .deps/elflint.Tpo -c -o elflint.o elflint.c
[make 2021-10-01 12:18:15] elflint.c: In function 'check_sections':
[make 2021-10-01 12:18:15] elflint.c:4105:48: error: null pointer dereference [-Werror=null-dereference]
[make 2021-10-01 12:18:15]  4105 |                                  idx < databits->d_size && ! bad;
[make 2021-10-01 12:18:15]       |                                        ~~~~~~~~^~~~~~~~
[make 2021-10-01 12:18:18] cc1: all warnings being treated as errors
[make 2021-10-01 12:18:18] make[2]: *** [Makefile:799: elflint.o] Error 1
[make 2021-10-01 12:18:18] make[1]: *** [Makefile:532: all-recursive] Error 1
[make 2021-10-01 12:18:18] make: *** [Makefile:448: all] Error 2


As it is tested beforehand that we should not run into this, this
patch should fix the warning:


diff --git a/src/elflint.c b/src/elflint.c
index 1ce75684..ef7725ce 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -4102,7 +4102,7 @@ section [%2zu] '%s' has type NOBITS but is read from the file in segment of prog
 			    bad = (databits == NULL
 				   || databits->d_size != shdr->sh_size);
 			    for (size_t idx = 0;
-				 idx < databits->d_size && ! bad;
+				 ! bad && idx < databits->d_size;
 				 idx++)
 			      bad = ((char *) databits->d_buf)[idx] != 0;
 


Please keep me Cc'ed as I'm not subscribed.

Thanks,
  Jan-Benedict

-- 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

             reply	other threads:[~2021-10-05 15:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05 15:32 Jan-Benedict Glaw [this message]
2021-10-06 21:44 ` Mark Wielaard
2021-10-05 15:36 Jan-Benedict Glaw
2021-10-06 21:55 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211005153216.fadk42msbpz4xvx5@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).