public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: binutils@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PUSHED] opcodes/arm: silence compiler warning about uninitialized variable use
Date: Tue,  1 Nov 2022 10:57:24 +0000	[thread overview]
Message-ID: <20221101105724.1527333-1-aburgess@redhat.com> (raw)

After I pushed this series:

  https://sourceware.org/pipermail/binutils/2022-October/123250.html

I managed to break .... pretty much all the buildbot builds :/

I've gone ahead and pushed the patch below as an emergency fix which
should resolve all the build problems.

If anyone disagrees with the fix here, please just let me know and I
can put together something inline with any feedback.

Sorry for the breakage.

Andrew

---

The earlier commit:

  commit 6576bffe6cbbb53c5756b2fccd2593ba69b74cdf
  Date:   Thu Jul 7 13:43:45 2022 +0100

      opcodes/arm: add disassembler styling for arm

was causing a compiler warning about a possible uninitialized variable
usage within opcodes/arm-dis.c.

The problem is in print_mve_unpredictable, and relates to the reason
variable, which is set by a switch table.

Currently the switch table does cover every valid value, though there
is no default case.  The variable switched on is passed in as an
argument to the print_mve_unpredictable function.

Looking at how print_mve_unpredictable is used, there is only one use,
the second argument is the one that is used for the switch table,
looking at how this argument is set, I don't believe it is possible
for this argument to take an invalid value.

So, I think the compiler warning is a false positive.  As such, my
proposed solution is to initialize the reason variable to the string
"??", this will silence the warning, and the "??" string should never
end up being printed.
---
 opcodes/arm-dis.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c
index 6d302ec50ba..101b3f84dfe 100644
--- a/opcodes/arm-dis.c
+++ b/opcodes/arm-dis.c
@@ -7234,7 +7234,9 @@ print_mve_unpredictable (struct disassemble_info *info,
 {
   void *stream = info->stream;
   fprintf_styled_ftype func = info->fprintf_styled_func;
-  const char *reason;
+  /* Initialize REASON to avoid compiler warning about uninitialized
+     usage, though such usage should be impossible.  */
+  const char *reason = "??";
 
   switch (unpredict_code)
     {
-- 
2.25.4


             reply	other threads:[~2022-11-01 10:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01 10:57 Andrew Burgess [this message]
2022-11-01 11:18 ` [PUSHED] opcodes/arm: don't pass non-string literal to printf like function Andrew Burgess
2022-11-04 11:01   ` [PUSHED] opcodes/arm: silence compiler warning about uninitialized variable use Andrew Burgess

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=20221101105724.1527333-1-aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=binutils@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).