diff options
author | Alan Modra <amodra@gmail.com> | 2023-08-07 20:59:08 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-08-11 16:36:11 +0930 |
commit | e416bd75c3fd471c1e0222a72b17f6c585b37e93 (patch) | |
tree | 6686dd0a3789a90fbe7969699a3ea3845658f73b /bfd/coff-rs6000.c | |
parent | 934ee74bc0d04b866968f3aba0dc16fe7bccb1d9 (diff) | |
download | gdb-e416bd75c3fd471c1e0222a72b17f6c585b37e93.zip gdb-e416bd75c3fd471c1e0222a72b17f6c585b37e93.tar.gz gdb-e416bd75c3fd471c1e0222a72b17f6c585b37e93.tar.bz2 |
warn unused result for bfd IO functions
This patch fixes all the warnings I found in bfd, binutils and ld,
plus some bitrotted COFF_GO32 code that tried to allocate -168ul
bytes. When the malloc fail was reported these testsuite fails
resulted:
i386-go32 +FAIL: go32 stub
i386-go32 +ERROR: tcl error sourcing /home/alan/src/binutils-gdb/ld/testsuite/ld-i386/i386.exp.
i386-go32 +ERROR: couldn't open "tmpdir/go32stub": no such file or directory
i386-go32 +FAIL: ld-scripts/sane1
i386-go32 +FAIL: ld-scripts/assign-loc
i386-go32 +FAIL: ld-scripts/pr18963
This does result in some warnings in gdb which are fixed in a followup
patch.
bfd/
* bfdio.c (bfd_read, bfd_write): Add ATTRIBUTE_WARN_UNUSED_RESULT.
(bfd_tell, bfd_stat, bfd_seek, bfd_mmap): Likewise.
* bfd-in2.h: Regenerate.
* coff-rs6000.c (xcoff_write_armap_big) Don't ignore bfd_write
return value.
(xcoff_generate_rtinit): Likewise. Also free data_buffer and
string_table before returning.
* coff64-rs6000.c (xcoff64_generate_rtinit): Likewise.
* coff-stgo32.c (go32exe_check_format): Don't ignore bfd_seek
return value.
* coffcode.h (coff_apply_checksum): Don't ignore bfd_write return.
(coff_write_object_contents <COFF_GO32>): Likewise, and bfd_malloc.
Fix bitrotted code to look for first section with non-zero filepos.
* elf64-ia64-vms.c (elf64_vms_write_shdrs_and_ehdr): Don't ignore
bfd_seek or bfd_write return values.
* pef.c (bfd_pef_scan_section): Likewise.
(bfd_pef_read_header, bfd_pef_xlib_read_header): Likewise.
* vms-misc.c (_bfd_vms_output_end): Likewise. Return status.
* vms.h (_bfd_vms_output_end): Update prototype.
* vms-alpha.c: Pass _bfd_vms_output_end status up call chains.
* wasm-module.c (wasm_compute_custom_section_file_position): Don't
ignore bfd_seek or bfd_write return values.
(wasm_compute_section_file_positions): Likewise.
* xsym.c (bfd_sym_scan): Don't ignore bfd_seek return value.
(bfd_sym_read_name_table): Likewise.
binutils/
* ar.c (print_contents, extract_file): Don't ignore bfd_seek
return value.
ld/
* pdb.c (create_section_contrib_substream): Don't ignore bfd_seek
return value.
(create_section_header_stream): Likewise.
* pe-dll.c (pe_get16, pe_get32): Add fail param to return results
from bfd_seek and bfd_read.
(pe_implied_import_dll): Handle these fails, and other bfd_seek
and bfd_read return values.
Diffstat (limited to 'bfd/coff-rs6000.c')
-rw-r--r-- | bfd/coff-rs6000.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 06d0fd8..7dd80a5 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -2193,8 +2193,12 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED, } } - bfd_write (symbol_table, symbol_table_size, abfd); - + if (bfd_write (symbol_table, symbol_table_size, abfd) + != symbol_table_size) + { + free (symbol_table); + return false; + } free (symbol_table); prevoff = nextoff; @@ -2273,8 +2277,12 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED, } } - bfd_write (symbol_table, symbol_table_size, abfd); - + if (bfd_write (symbol_table, symbol_table_size, abfd) + != symbol_table_size) + { + free (symbol_table); + return false; + } free (symbol_table); PRINT20 (fhdr->symoff64, nextoff); @@ -4204,7 +4212,10 @@ xcoff_generate_rtinit (bfd *abfd, const char *init, const char *fini, string_table_size += 4; string_table = (bfd_byte *) bfd_zmalloc (string_table_size); if (string_table == NULL) - return false; + { + free (data_buffer); + return false; + } val = string_table_size; bfd_h_put_32 (abfd, val, &string_table[0]); @@ -4354,18 +4365,21 @@ xcoff_generate_rtinit (bfd *abfd, const char *init, const char *fini, filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ; bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext); - bfd_write (filehdr_ext, FILHSZ, abfd); bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext); - bfd_write (scnhdr_ext, SCNHSZ, abfd); - bfd_write (data_buffer, data_buffer_size, abfd); - bfd_write (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd); - bfd_write (syment_ext, filehdr.f_nsyms * SYMESZ, abfd); - bfd_write (string_table, string_table_size, abfd); - + bool ret = true; + if (bfd_write (filehdr_ext, FILHSZ, abfd) != FILHSZ + || bfd_write (scnhdr_ext, SCNHSZ, abfd) != SCNHSZ + || bfd_write (data_buffer, data_buffer_size, abfd) != data_buffer_size + || (bfd_write (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd) + != scnhdr.s_nreloc * RELSZ) + || (bfd_write (syment_ext, filehdr.f_nsyms * SYMESZ, abfd) + != (bfd_size_type) filehdr.f_nsyms * SYMESZ) + || bfd_write (string_table, string_table_size, abfd) != string_table_size) + ret = false; + + free (string_table); free (data_buffer); - data_buffer = NULL; - - return true; + return ret; } |