From patchwork Tue Oct 5 15:32:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan-Benedict Glaw X-Patchwork-Id: 45899 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 484EC3857C50 for ; Tue, 5 Oct 2021 15:32:23 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from lug-owl.de (lug-owl.de [188.68.32.151]) by sourceware.org (Postfix) with ESMTP id 11F1F385800F for ; Tue, 5 Oct 2021 15:32:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 11F1F385800F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lug-owl.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lug-owl.de Received: by lug-owl.de (Postfix, from userid 1001) id 81E8741F18; Tue, 5 Oct 2021 17:32:16 +0200 (CEST) Date: Tue, 5 Oct 2021 17:32:16 +0200 From: Jan-Benedict Glaw To: elfutils-devel@sourceware.org Subject: [PATCH] Tests: Fix warning in show-die-info.c Message-ID: <20211005153216.fadk42msbpz4xvx5@lug-owl.de> MIME-Version: 1.0 Content-Disposition: inline X-Operating-System: Linux chamaeleon 5.8.0-0.bpo.2-amd64 X-gpg-fingerprint: 250D 3BCF 7127 0D8C A444 A961 1DBD 5E75 8399 E1BB X-gpg-key: wwwkeys.de.pgp.net X-Echelon-Enable: howto poison arsenous mail psychological biological nuclear warfare test the bombastical terror of flooding the spy listeners explosion sex drugs and rock'n'roll X-TKUeV: howto poison arsenous mail psychological biological nuclear warfare test the bombastical terror of flooding the spy listeners explosion sex drugs and rock'n'roll X-message-flag: Please send plain text messages only. Do not send HTML emails. Thank you. User-Agent: NeoMutt/20170113 (1.7.2) X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" 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: Please keep me Cc'ed as I'm not subscribed. Thanks, Jan-Benedict 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;