From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 8CB843856DF7 for ; Thu, 30 Jun 2022 12:42:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CB843856DF7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 525D330146AC; Thu, 30 Jun 2022 14:42:14 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id C2888407903B; Thu, 30 Jun 2022 14:42:13 +0200 (CEST) From: Mark Wielaard To: dwz@sourceware.org Cc: Mark Wielaard Subject: [PATCH] Always assign svalue when checking and reporting negative values Date: Thu, 30 Jun 2022 14:42:08 +0200 Message-Id: <20220630124208.22881-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 12:42:16 -0000 GCC12 warns: In file included from /usr/include/error.h:59, from dwz.c:23: In function ‘error’, inlined from ‘checksum_die’ at dwz.c:3364:7: /usr/include/bits/error.h:42:5: warning: ‘svalue’ may be used uninitialized [-Wmaybe-uninitialized] 42 | __error_alias (__status, __errnum, __format, __va_arg_pack ()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dwz.c: In function ‘checksum_die’: dwz.c:3354:25: note: ‘svalue’ was declared here 3354 | int64_t svalue = read_sleb128 (ptr); | ^~~~~~ It is correct. We jump to the common error reporting label negative where we expect svalue to be set so we can print it in the error message. But it isn't in all places. Fix this by explicitly assigning svalue first in all places we goto negative on failure. * dwz.c (checksum_die): Always assign svalue when checking and reporting on unexpected negative values. --- https://code.wildebeest.org/git/user/mjw/dwz/commit/?h=checksum_die_svalue dwz.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dwz.c b/dwz.c index 7af1a03..ac0a540 100644 --- a/dwz.c +++ b/dwz.c @@ -3278,6 +3278,7 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die) size_t len = 0; unsigned char *old_ptr; bool handled = false; + int64_t svalue; uint64_t value; while (form == DW_FORM_indirect) @@ -3351,7 +3352,7 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die) value = read_uleb128 (ptr); handled = true; break; case DW_FORM_sdata: { - int64_t svalue = read_sleb128 (ptr); + svalue = read_sleb128 (ptr); if (svalue >= 0) { value = svalue; @@ -3369,9 +3370,10 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die) } case DW_FORM_implicit_const: { - if (t->values[i] >= 0) + svalue = t->values[i]; + if (svalue >= 0) { - value = t->values[i]; + value = svalue; handled = true; break; } @@ -3457,7 +3459,7 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die) value = read_uleb128 (ptr); handled = true; break; case DW_FORM_sdata: { - int64_t svalue = read_sleb128 (ptr); + svalue = read_sleb128 (ptr); if (svalue >= 0) { value = svalue; @@ -3468,9 +3470,10 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die) goto negative; } case DW_FORM_implicit_const: - if (t->values[i] >= 0) + svalue = t->values[i]; + if (svalue >= 0) { - value = t->values[i]; + value = svalue; handled = true; break; } -- 2.18.4