gdb: warn unused result for bfd IO functions
Andrew Burgess
aburgess@redhat.com
Fri Aug 11 12:15:36 GMT 2023
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);
More information about the Binutils
mailing list