public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Alan Modra <amodra@gmail.com>,
	binutils@sourceware.org, gdb-patches@sourceware.org
Subject: Re: gdb: warn unused result for bfd IO functions
Date: Fri, 11 Aug 2023 13:15:36 +0100	[thread overview]
Message-ID: <87350pepw7.fsf@redhat.com> (raw)
In-Reply-To: <ZNRbSREoB52gfDWx@squeak.grove.modra.org>

Alan Modra via Binutils <binutils@sourceware.org> writes:

> From 3dd00a9f25bc78028ba4b3820b45d34f51c4a25d Mon Sep 17 00:00:00 2001
> From: Alan Modra <amodra@gmail.com>
> Date: Wed, 9 Aug 2023 09:58:36 +0930
> Subject: 
>
> This fixes the compilation warnings introduced by my bfdio.c patch.
>
> The removed bfd_seeks in coff_symfile_read date back to 1994, commit
> 7f4c859520, prior to which the file used stdio rather than bfd to read
> symbols.  Since it now uses bfd to read the file there should be no
> need to synchronise to bfd's idea of the file position.  I also fixed
> a potential uninitialised memory access.
>
> OK to apply?

I had a look through, this all looks OK, except I think we can easily
avoid adding a new 'goto' with the patch below.

If you're happy to take this change then:

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

---

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 34360eb72f1..0d76ebdbfce 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -343,30 +343,29 @@ read_pe_exported_syms (minimal_symbol_reader &reader,
 	     || strcmp (target, "pei-i386") == 0
 	     || strcmp (target, "pe-arm-wince-little") == 0
 	     || strcmp (target, "pei-arm-wince-little") == 0);
+
+  /* Possibly print a debug message about DLL not having a valid format.  */
+  auto maybe_print_debug_msg = [&] () -> void {
+    if (debug_coff_pe_read)
+      gdb_printf (gdb_stdlog, _("%s doesn't appear to be a DLL\n"),
+		  bfd_get_filename (dll));
+  };
+
   if (!is_pe32 && !is_pe64)
-    {
-      /* This is not a recognized PE format file.  Abort now, because
-	 the code is untested on anything else.  *FIXME* test on
-	 further architectures and loosen or remove this test.  */
-    notdll:
-      if (debug_coff_pe_read)
-	gdb_printf (gdb_stdlog, _("%s doesn't appear to be a DLL\n"),
-		    bfd_get_filename (dll));
-      return;
-    }
+    return maybe_print_debug_msg ();
 
   /* Get pe_header, optional header and numbers of export entries.  */
   bool fail = false;
   pe_header_offset = pe_get32 (dll, 0x3c, &fail);
   if (fail)
-    goto notdll;
+    return maybe_print_debug_msg ();
   opthdr_ofs = pe_header_offset + 4 + 20;
   if (is_pe64)
     num_entries = pe_get32 (dll, opthdr_ofs + 108, &fail);
   else
     num_entries = pe_get32 (dll, opthdr_ofs + 92, &fail);
   if (fail)
-    goto notdll;
+    return maybe_print_debug_msg ();
 
   if (num_entries < 1)		/* No exports.  */
     return;
@@ -381,13 +380,13 @@ read_pe_exported_syms (minimal_symbol_reader &reader,
       export_opthdrsize = pe_get32 (dll, opthdr_ofs + 100, &fail);
     }
   if (fail)
-    goto notdll;
+    return maybe_print_debug_msg ();
 
   nsections = pe_get16 (dll, pe_header_offset + 4 + 2, &fail);
   secptr = (pe_header_offset + 4 + 20 +
 	    pe_get16 (dll, pe_header_offset + 4 + 16, &fail));
   if (fail)
-    goto notdll;
+    return maybe_print_debug_msg ();
   expptr = 0;
   export_size = 0;
 
@@ -454,7 +453,7 @@ read_pe_exported_syms (minimal_symbol_reader &reader,
       if (fail
 	  || bfd_seek (dll, secptr1 + 0, SEEK_SET) != 0
 	  || bfd_read (sec_name, SCNNMLEN, dll) != SCNNMLEN)
-	goto notdll;
+	return maybe_print_debug_msg ();
       sec_name[SCNNMLEN] = '\0';
 
       sectix = read_pe_section_index (sec_name);
@@ -495,7 +494,7 @@ read_pe_exported_syms (minimal_symbol_reader &reader,
 
   if (bfd_seek (dll, expptr, SEEK_SET) != 0
       || bfd_read (expdata, export_size, dll) != export_size)
-    goto notdll;
+    return maybe_print_debug_msg ();
   erva = expdata - export_rva;
 
   nexp = pe_as32 (expdata + 24);


      reply	other threads:[~2023-08-11 12:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ZNRamusOvj0f+x5T@squeak.grove.modra.org>
2023-08-10  3:36 ` Alan Modra
2023-08-11 12:15   ` Andrew Burgess [this message]

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=87350pepw7.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@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).