public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: dwz@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] Always assign svalue when checking and reporting negative values
Date: Thu, 30 Jun 2022 14:42:08 +0200	[thread overview]
Message-ID: <20220630124208.22881-1-mark@klomp.org> (raw)

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


             reply	other threads:[~2022-06-30 12:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 12:42 Mark Wielaard [this message]
2022-07-04 13:05 ` 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=20220630124208.22881-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=dwz@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).