char *bfd_demangle (bfd *, const char *, int);
/* Extracted from bfdio.c. */
-bfd_size_type bfd_read (void *, bfd_size_type, bfd *);
+bfd_size_type bfd_read (void *, bfd_size_type, bfd *)
+ATTRIBUTE_WARN_UNUSED_RESULT;
-bfd_size_type bfd_write (const void *, bfd_size_type, bfd *);
+bfd_size_type bfd_write (const void *, bfd_size_type, bfd *)
+ATTRIBUTE_WARN_UNUSED_RESULT;
-file_ptr bfd_tell (bfd *);
+file_ptr bfd_tell (bfd *) ATTRIBUTE_WARN_UNUSED_RESULT;
int bfd_flush (bfd *);
-int bfd_stat (bfd *, struct stat *);
+int bfd_stat (bfd *, struct stat *) ATTRIBUTE_WARN_UNUSED_RESULT;
-int bfd_seek (bfd *, file_ptr, int);
+int bfd_seek (bfd *, file_ptr, int) ATTRIBUTE_WARN_UNUSED_RESULT;
long bfd_get_mtime (bfd *abfd);
void *bfd_mmap (bfd *abfd, void *addr, bfd_size_type len,
int prot, int flags, file_ptr offset,
- void **map_addr, bfd_size_type *map_len);
+ void **map_addr, bfd_size_type *map_len)
+ATTRIBUTE_WARN_UNUSED_RESULT;
/* Extracted from bfdwin.c. */
struct _bfd_window_internal;
bfd_read
SYNOPSIS
- bfd_size_type bfd_read (void *, bfd_size_type, bfd *);
+ bfd_size_type bfd_read (void *, bfd_size_type, bfd *)
+ ATTRIBUTE_WARN_UNUSED_RESULT;
DESCRIPTION
Attempt to read SIZE bytes from ABFD's iostream to PTR.
bfd_write
SYNOPSIS
- bfd_size_type bfd_write (const void *, bfd_size_type, bfd *);
+ bfd_size_type bfd_write (const void *, bfd_size_type, bfd *)
+ ATTRIBUTE_WARN_UNUSED_RESULT;
DESCRIPTION
Attempt to write SIZE bytes to ABFD's iostream from PTR.
bfd_tell
SYNOPSIS
- file_ptr bfd_tell (bfd *);
+ file_ptr bfd_tell (bfd *) ATTRIBUTE_WARN_UNUSED_RESULT;
DESCRIPTION
Return ABFD's iostream file position.
bfd_stat
SYNOPSIS
- int bfd_stat (bfd *, struct stat *);
+ int bfd_stat (bfd *, struct stat *) ATTRIBUTE_WARN_UNUSED_RESULT;
DESCRIPTION
Call fstat on ABFD's iostream. Return 0 on success, and a
bfd_seek
SYNOPSIS
- int bfd_seek (bfd *, file_ptr, int);
+ int bfd_seek (bfd *, file_ptr, int) ATTRIBUTE_WARN_UNUSED_RESULT;
DESCRIPTION
Call fseek on ABFD's iostream. Return 0 on success, and a
SYNOPSIS
void *bfd_mmap (bfd *abfd, void *addr, bfd_size_type len,
int prot, int flags, file_ptr offset,
- void **map_addr, bfd_size_type *map_len);
+ void **map_addr, bfd_size_type *map_len)
+ ATTRIBUTE_WARN_UNUSED_RESULT;
DESCRIPTION
Return mmap()ed region of the file, if possible and implemented.
}
}
- 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;
}
}
- 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);
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]);
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;
}
/* Save now the stub to be used later. Put the stub data to a temporary
location first as tdata still does not exist. It may not even
be ever created if we are just checking the file format of ABFD. */
- bfd_seek (abfd, 0, SEEK_SET);
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0)
+ goto fail;
go32exe_temp_stub = bfd_malloc (stubsize);
if (go32exe_temp_stub == NULL)
goto fail;
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_put_32 (abfd, val, &string_table[0]);
filehdr.f_symptr = data_scnhdr.s_relptr + data_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, &text_scnhdr, &scnhdr_ext[SCNHSZ * 0]);
bfd_coff_swap_scnhdr_out (abfd, &data_scnhdr, &scnhdr_ext[SCNHSZ * 1]);
bfd_coff_swap_scnhdr_out (abfd, &bss_scnhdr, &scnhdr_ext[SCNHSZ * 2]);
- bfd_write (scnhdr_ext, 3 * SCNHSZ, abfd);
- bfd_write (data_buffer, data_buffer_size, abfd);
- bfd_write (reloc_ext, data_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, 3 * SCNHSZ, abfd) != 3 * SCNHSZ
+ || bfd_write (data_buffer, data_buffer_size, abfd) != data_buffer_size
+ || (bfd_write (reloc_ext, data_scnhdr.s_nreloc * RELSZ, abfd)
+ != data_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;
}
/* The typical dynamic reloc. */
return false;
checksum = 0;
- bfd_write (&checksum, 4, abfd);
+ if (bfd_write (&checksum, 4, abfd) != 4)
+ return false;
if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
return false;
if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
return false;
- bfd_write (&checksum, 4, abfd);
-
- return true;
+ return bfd_write (&checksum, 4, abfd) == 4;
}
#endif /* COFF_IMAGE_WITH_PE */
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
/* Pad section headers. */
- if ((abfd->flags & EXEC_P) && abfd->sections != NULL)
+ if ((abfd->flags & EXEC_P) != 0)
{
- file_ptr cur_ptr = scn_base
- + abfd->section_count * bfd_coff_scnhsz (abfd);
- long fill_size = (abfd->sections->filepos - cur_ptr);
- bfd_byte *b = bfd_zmalloc (fill_size);
- if (b)
+ asection *s = abfd->sections;
+ while (s != NULL && s->filepos == 0)
+ s = s->next;
+ if (s != NULL)
{
- bfd_write (b, fill_size, abfd);
- free (b);
+ file_ptr cur_ptr
+ = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
+ file_ptr fill_size = s->filepos - cur_ptr;
+ if (fill_size > 0)
+ {
+ bfd_byte *b = bfd_zmalloc (fill_size);
+ if (!b)
+ return false;
+ if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
+ {
+ free (b);
+ return false;
+ }
+ free (b);
+ }
}
}
#endif
static bool
elf64_vms_close_and_cleanup (bfd *abfd)
{
+ bool ret = true;
if (bfd_get_format (abfd) == bfd_object)
{
long isize;
isize = bfd_get_size (abfd);
if ((isize & 7) != 0)
{
- int ishort = 8 - (isize & 7);
+ unsigned int ishort = 8 - (isize & 7);
uint64_t pad = 0;
- bfd_seek (abfd, isize, SEEK_SET);
- bfd_write (&pad, ishort, abfd);
+ if (bfd_seek (abfd, isize, SEEK_SET) != 0
+ || bfd_write (&pad, ishort, abfd) != ishort)
+ ret = false;
}
}
- return _bfd_generic_close_and_cleanup (abfd);
+ return _bfd_generic_close_and_cleanup (abfd) && ret;
}
/* Add symbols from an ELF object file to the linker hash table. */
{
unsigned char buf[28];
- bfd_seek (abfd, section->header_offset, SEEK_SET);
- if (bfd_read (buf, 28, abfd) != 28)
+ if (bfd_seek (abfd, section->header_offset, SEEK_SET) != 0
+ || bfd_read (buf, 28, abfd) != 28)
return -1;
section->name_offset = bfd_h_get_32 (abfd, buf);
{
unsigned char buf[40];
- bfd_seek (abfd, 0, SEEK_SET);
-
- if (bfd_read (buf, 40, abfd) != 40)
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0
+ || bfd_read (buf, 40, abfd) != 40)
return -1;
header->tag1 = bfd_getb32 (buf);
{
unsigned char buf[80];
- bfd_seek (abfd, 0, SEEK_SET);
-
- if (bfd_read (buf, sizeof buf, abfd) != sizeof buf)
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0
+ || bfd_read (buf, sizeof buf, abfd) != sizeof buf)
return -1;
header->tag1 = bfd_getb32 (buf);
/* Write an EMH/MHD record. */
-static void
+static bool
_bfd_vms_write_emh (bfd *abfd)
{
struct vms_rec_wr *recwr = &PRIV (recwr);
_bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
_bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH);
_bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
- _bfd_vms_output_end (abfd, recwr);
+ return _bfd_vms_output_end (abfd, recwr);
}
/* Write an EMH/LMN record. */
-static void
+static bool
_bfd_vms_write_lmn (bfd *abfd, const char *name)
{
char version [64];
snprintf (version, sizeof (version), "%s %d.%d.%d", name,
ver / 10000, (ver / 100) % 100, ver % 100);
_bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version));
- _bfd_vms_output_end (abfd, recwr);
+ return _bfd_vms_output_end (abfd, recwr);
}
_bfd_vms_output_long (recwr, 0);
}
- _bfd_vms_output_end (abfd, recwr);
- return true;
+ return _bfd_vms_output_end (abfd, recwr);
}
static void *
struct vms_rec_wr *recwr = &PRIV (recwr);
unsigned int i;
- _bfd_vms_write_emh (abfd);
- _bfd_vms_write_lmn (abfd, "GNU LD");
+ if (!_bfd_vms_write_emh (abfd)
+ || !_bfd_vms_write_lmn (abfd, "GNU LD"))
+ return false;
/* PSC for the absolute section. */
_bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
_bfd_vms_output_long (recwr, 0);
_bfd_vms_output_counted (recwr, ".$$ABS$$.");
_bfd_vms_output_end_subrec (recwr);
- _bfd_vms_output_end (abfd, recwr);
+ if (!_bfd_vms_output_end (abfd, recwr))
+ return false;
for (i = 0; i < PRIV (gsd_sym_count); i++)
{
_bfd_vms_output_long (recwr, 0);
_bfd_vms_output_counted (recwr, sym->name);
_bfd_vms_output_end_subrec (recwr);
- if ((i % 5) == 4)
- _bfd_vms_output_end (abfd, recwr);
+ if ((i % 5) == 4
+ && !_bfd_vms_output_end (abfd, recwr))
+ return false;
}
- if ((i % 5) != 0)
- _bfd_vms_output_end (abfd, recwr);
+ if ((i % 5) != 0
+ && !_bfd_vms_output_end (abfd, recwr))
+ return false;
if (!_bfd_vms_write_eeom (abfd))
return false;
/* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */
if (_bfd_vms_output_check (recwr, 64) < 0)
{
- _bfd_vms_output_end (abfd, recwr);
+ if (!_bfd_vms_output_end (abfd, recwr))
+ return false;
_bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
_bfd_vms_output_long (recwr, 0);
}
bytes for a possible ABS section. */
if (_bfd_vms_output_check (recwr, 80 + 16) < 0)
{
- _bfd_vms_output_end (abfd, recwr);
+ if (!_bfd_vms_output_end (abfd, recwr))
+ return false;
_bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
_bfd_vms_output_long (recwr, 0);
}
}
_bfd_vms_output_alignment (recwr, 8);
- _bfd_vms_output_end (abfd, recwr);
-
- return true;
+ return _bfd_vms_output_end (abfd, recwr);
}
/* Write object header for bfd abfd. Return FALSE on error. */
_bfd_vms_output_alignment (recwr, 2);
- _bfd_vms_write_emh (abfd);
- _bfd_vms_write_lmn (abfd, "GNU AS");
+ if (!_bfd_vms_write_emh (abfd)
+ || !_bfd_vms_write_lmn (abfd, "GNU AS"))
+ return false;
/* SRC. */
_bfd_vms_output_begin (recwr, EOBJ__C_EMH);
if (symnum == abfd->symcount)
_bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname"));
- _bfd_vms_output_end (abfd, recwr);
+ if (!_bfd_vms_output_end (abfd, recwr))
+ return false;
/* TTL. */
_bfd_vms_output_begin (recwr, EOBJ__C_EMH);
_bfd_vms_output_short (recwr, EMH__C_TTL);
_bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL"));
- _bfd_vms_output_end (abfd, recwr);
+ if (!_bfd_vms_output_end (abfd, recwr))
+ return false;
/* CPR. */
_bfd_vms_output_begin (recwr, EOBJ__C_EMH);
_bfd_vms_output_dump (recwr,
(unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
39);
- _bfd_vms_output_end (abfd, recwr);
-
- return true;
+ return _bfd_vms_output_end (abfd, recwr);
}
/* Part 4.6, relocations. */
/* Close the etir/etbt record. */
-static void
+static bool
end_etir_record (bfd * abfd)
{
struct vms_rec_wr *recwr = &PRIV (recwr);
- _bfd_vms_output_end (abfd, recwr);
+ return _bfd_vms_output_end (abfd, recwr);
}
static void
/* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual
address VADDR in section specified by SEC_INDEX and NAME. */
-static void
+static bool
sto_imm (bfd *abfd, asection *section,
bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr)
{
if (_bfd_vms_output_check (recwr, size) < 0)
{
/* Doesn't fit, split ! */
- end_etir_record (abfd);
+ if (!end_etir_record (abfd))
+ return false;
start_etir_or_etbt_record (abfd, section, vaddr);
cptr += size;
ssize -= size;
}
+ return true;
}
-static void
+static bool
etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen)
{
if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0)
{
/* Not enough room in this record. Close it and open a new one. */
- end_etir_record (abfd);
+ if (!end_etir_record (abfd))
+ return false;
start_etir_or_etbt_record (abfd, section, vaddr);
}
+ return true;
}
/* Return whether RELOC must be deferred till the end. */
_bfd_error_handler (_("size error in section %pA"),
section);
size = addr - curr_addr;
- sto_imm (abfd, section, size, curr_data, curr_addr);
+ if (!sto_imm (abfd, section, size, curr_data, curr_addr))
+ return false;
curr_data += size;
curr_addr += size;
}
{
bfd_vma addend = rptr->addend;
slen = strlen ((char *) sym->name);
- etir_output_check (abfd, section, curr_addr, slen);
+ if (!etir_output_check (abfd, section, curr_addr, slen))
+ return false;
if (addend)
{
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
}
else if (bfd_is_abs_section (sym->section))
{
- etir_output_check (abfd, section, curr_addr, 16);
+ if (!etir_output_check (abfd, section, curr_addr, 16))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
_bfd_vms_output_long (recwr, (unsigned long) sym->value);
_bfd_vms_output_end_subrec (recwr);
}
else
{
- etir_output_check (abfd, section, curr_addr, 32);
+ if (!etir_output_check (abfd, section, curr_addr, 32))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
_bfd_vms_output_long (recwr,
(unsigned long) sec->target_index);
{
bfd_vma addend = rptr->addend;
slen = strlen ((char *) sym->name);
- etir_output_check (abfd, section, curr_addr, slen);
+ if (!etir_output_check (abfd, section, curr_addr, slen))
+ return false;
if (addend)
{
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
}
else if (bfd_is_abs_section (sym->section))
{
- etir_output_check (abfd, section, curr_addr, 16);
+ if (!etir_output_check (abfd, section, curr_addr, 16))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
_bfd_vms_output_quad (recwr, sym->value);
_bfd_vms_output_end_subrec (recwr);
}
else
{
- etir_output_check (abfd, section, curr_addr, 32);
+ if (!etir_output_check (abfd, section, curr_addr, 32))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
_bfd_vms_output_long (recwr,
(unsigned long) sec->target_index);
break;
case ALPHA_R_HINT:
- sto_imm (abfd, section, size, curr_data, curr_addr);
+ if (!sto_imm (abfd, section, size, curr_data, curr_addr))
+ return false;
break;
case ALPHA_R_LINKAGE:
size = 16;
- etir_output_check (abfd, section, curr_addr, 64);
+ if (!etir_output_check (abfd, section, curr_addr, 64))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
_bfd_vms_output_long
(recwr, (unsigned long) rptr->addend);
case ALPHA_R_CODEADDR:
slen = strlen ((char *) sym->name);
- etir_output_check (abfd, section, curr_addr, slen);
+ if (!etir_output_check (abfd, section, curr_addr, slen))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA);
_bfd_vms_output_counted (recwr, sym->name);
_bfd_vms_output_end_subrec (recwr);
case ALPHA_R_NOP:
udata
= (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
- etir_output_check (abfd, section, curr_addr,
- 32 + 1 + strlen (udata->origname));
+ if (!etir_output_check (abfd, section, curr_addr,
+ 32 + 1 + strlen (udata->origname)))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL);
_bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
_bfd_vms_output_long
case ALPHA_R_LDA:
udata
= (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
- etir_output_check (abfd, section, curr_addr,
- 32 + 1 + strlen (udata->origname));
+ if (!etir_output_check (abfd, section, curr_addr,
+ 32 + 1 + strlen (udata->origname)))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL);
_bfd_vms_output_long
(recwr, (unsigned long) udata->lkindex + 1);
case ALPHA_R_BOH:
udata
= (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
- etir_output_check (abfd, section, curr_addr,
- 32 + 1 + strlen (udata->origname));
+ if (!etir_output_check (abfd, section, curr_addr,
+ 32 + 1 + strlen (udata->origname)))
+ return false;
_bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL);
_bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
_bfd_vms_output_long
return false;
}
size = section->size - curr_addr;
- sto_imm (abfd, section, size, curr_data, curr_addr);
+ if (!sto_imm (abfd, section, size, curr_data, curr_addr))
+ return false;
curr_data += size;
curr_addr += size;
}
else /* (section->flags & SEC_RELOC) */
- sto_imm (abfd, section, section->size, section->contents, 0);
+ if (!sto_imm (abfd, section, section->size, section->contents, 0))
+ return false;
- end_etir_record (abfd);
+ if (!end_etir_record (abfd))
+ return false;
}
_bfd_vms_output_alignment (recwr, 2);
/* Ends current record (and write it). */
-void
+bool
_bfd_vms_output_end (bfd *abfd, struct vms_rec_wr *recwr)
{
vms_debug2 ((6, "_bfd_vms_output_end (size %u)\n", recwr->size));
BFD_ASSERT (recwr->subrec_offset == 0);
if (recwr->size == 0)
- return;
+ return true;
_bfd_vms_output_align (recwr, recwr->size);
converted to variable length (VAR) format. VAR format has a length
word first which must be explicitly output in UDF format. */
/* So, first the length word. */
- bfd_write (recwr->buf + 2, 2, abfd);
+ if (bfd_write (recwr->buf + 2, 2, abfd) != 2)
+ return false;
/* Align. */
if (recwr->size & 1)
recwr->buf[recwr->size++] = 0;
/* Then the record. */
- bfd_write (recwr->buf, (size_t) recwr->size, abfd);
+ if (bfd_write (recwr->buf, (size_t) recwr->size, abfd)
+ != (size_t) recwr->size)
+ return false;
recwr->size = 0;
+ return true;
}
/* Check remaining buffer size. Return what's left. */
extern void _bfd_vms_output_alignment (struct vms_rec_wr *, int);
extern void _bfd_vms_output_begin_subrec (struct vms_rec_wr *, int);
extern void _bfd_vms_output_end_subrec (struct vms_rec_wr *);
-extern void _bfd_vms_output_end (bfd *, struct vms_rec_wr *);
+extern bool _bfd_vms_output_end (bfd *, struct vms_rec_wr *);
extern int _bfd_vms_output_check (struct vms_rec_wr *, int);
extern void _bfd_vms_output_byte (struct vms_rec_wr *, unsigned);
extern void _bfd_vms_output_short (struct vms_rec_wr *, unsigned);
}
while (nl);
- bfd_seek (abfd, fs->pos, SEEK_SET);
- if (! wasm_write_uleb128 (abfd, 0)
+ if (bfd_seek (abfd, fs->pos, SEEK_SET) != 0
+ || ! wasm_write_uleb128 (abfd, 0)
|| ! wasm_write_uleb128 (abfd, payload_len)
|| ! wasm_write_uleb128 (abfd, name_len)
|| bfd_write (name, name_len, abfd) != name_len)
struct compute_section_arg fs;
unsigned int i;
- bfd_seek (abfd, (bfd_vma) 0, SEEK_SET);
-
- if (bfd_write (magic, sizeof (magic), abfd) != (sizeof magic)
+ if (bfd_seek (abfd, (bfd_vma) 0, SEEK_SET) != 0
+ || bfd_write (magic, sizeof (magic), abfd) != (sizeof magic)
|| bfd_write (vers, sizeof (vers), abfd) != sizeof (vers))
return false;
mdata->sbfd = abfd;
mdata->version = version;
- bfd_seek (abfd, 0, SEEK_SET);
- if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0
+ || bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
return -1;
mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
bfd_sym_version version = -1;
bfd_sym_data_struct *mdata;
- bfd_seek (abfd, 0, SEEK_SET);
- if (bfd_sym_read_version (abfd, &version) != 0)
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0
+ || bfd_sym_read_version (abfd, &version) != 0)
goto wrong;
mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
if (verbose)
printf ("\n<%s>\n\n", bfd_get_filename (abfd));
- bfd_seek (abfd, 0, SEEK_SET);
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0)
+ bfd_fatal (bfd_get_filename (abfd));
size = buf.st_size;
while (ncopied < size)
fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
size = buf.st_size;
- bfd_seek (abfd, 0, SEEK_SET);
+ if (bfd_seek (abfd, 0, SEEK_SET) != 0)
+ bfd_fatal (bfd_get_filename (abfd));
output_file = NULL;
if (size == 0)
for (unsigned int i = 0; i < abfd->section_count; i++)
{
- bfd_seek (abfd, offset, SEEK_SET);
-
- if (bfd_read (sect_flags + (i * sizeof (uint32_t)), sizeof (uint32_t),
- abfd) != sizeof (uint32_t))
+ if (bfd_seek (abfd, offset, SEEK_SET) != 0
+ || bfd_read (sect_flags + (i * sizeof (uint32_t)), sizeof (uint32_t),
+ abfd) != sizeof (uint32_t))
{
free (*data);
free (sect_flags);
scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
- bfd_seek (abfd, scn_base, SEEK_SET);
+ if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
+ return false;
len = section_count * sizeof (struct external_scnhdr);
buf = xmalloc (len);
handled, FALSE if not. */
static unsigned int
-pe_get16 (bfd *abfd, int where)
+pe_get16 (bfd *abfd, int where, bool *fail)
{
unsigned char b[2];
- bfd_seek (abfd, where, SEEK_SET);
- bfd_read (b, 2, abfd);
+ if (bfd_seek (abfd, where, SEEK_SET) != 0
+ || bfd_read (b, 2, abfd) != 2)
+ {
+ *fail = true;
+ return 0;
+ }
return b[0] + (b[1] << 8);
}
static unsigned int
-pe_get32 (bfd *abfd, int where)
+pe_get32 (bfd *abfd, int where, bool *fail)
{
unsigned char b[4];
- bfd_seek (abfd, where, SEEK_SET);
- bfd_read (b, 4, abfd);
+ if (bfd_seek (abfd, where, SEEK_SET) != 0
+ || bfd_read (b, 4, abfd) != 4)
+ {
+ *fail = true;
+ return 0;
+ }
return b[0] + (b[1] << 8) + (b[2] << 16) + ((unsigned) b[3] << 24);
}
/* PEI dlls seem to be bfd_objects. */
if (!bfd_check_format (dll, bfd_object))
{
+ notdll:
einfo (_("%X%P: %s: this doesn't appear to be a DLL\n"), filename);
return false;
}
/* Get pe_header, optional header and numbers of directory entries. */
- pe_header_offset = pe_get32 (dll, 0x3c);
+ bool fail = false;
+ pe_header_offset = pe_get32 (dll, 0x3c, &fail);
+ if (fail)
+ goto notdll;
opthdr_ofs = pe_header_offset + 4 + 20;
#ifdef pe_use_plus
- num_entries = pe_get32 (dll, opthdr_ofs + 92 + 4 * 4); /* & NumberOfRvaAndSizes. */
+ /* NumberOfRvaAndSizes. */
+ num_entries = pe_get32 (dll, opthdr_ofs + 92 + 4 * 4, &fail);
#else
- num_entries = pe_get32 (dll, opthdr_ofs + 92);
+ num_entries = pe_get32 (dll, opthdr_ofs + 92, &fail);
#endif
+ if (fail)
+ goto notdll;
/* No import or export directory entry. */
if (num_entries < 1)
return false;
#ifdef pe_use_plus
- export_rva = pe_get32 (dll, opthdr_ofs + 96 + 4 * 4);
- export_size = pe_get32 (dll, opthdr_ofs + 100 + 4 * 4);
+ export_rva = pe_get32 (dll, opthdr_ofs + 96 + 4 * 4, &fail);
+ export_size = pe_get32 (dll, opthdr_ofs + 100 + 4 * 4, &fail);
#else
- export_rva = pe_get32 (dll, opthdr_ofs + 96);
- export_size = pe_get32 (dll, opthdr_ofs + 100);
+ export_rva = pe_get32 (dll, opthdr_ofs + 96, &fail);
+ export_size = pe_get32 (dll, opthdr_ofs + 100, &fail);
#endif
+ if (fail)
+ goto notdll;
/* No export table - nothing to export. */
if (export_size == 0)
return false;
- nsections = pe_get16 (dll, pe_header_offset + 4 + 2);
+ nsections = pe_get16 (dll, pe_header_offset + 4 + 2, &fail);
secptr = (pe_header_offset + 4 + 20 +
- pe_get16 (dll, pe_header_offset + 4 + 16));
+ pe_get16 (dll, pe_header_offset + 4 + 16, &fail));
+ if (fail)
+ goto notdll;
expptr = 0;
/* Get the rva and size of the export section. */
{
char sname[8];
bfd_vma secptr1 = secptr + 40 * i;
- bfd_vma vaddr = pe_get32 (dll, secptr1 + 12);
- bfd_vma vsize = pe_get32 (dll, secptr1 + 16);
- bfd_vma fptr = pe_get32 (dll, secptr1 + 20);
+ bfd_vma vaddr = pe_get32 (dll, secptr1 + 12, &fail);
+ bfd_vma vsize = pe_get32 (dll, secptr1 + 16, &fail);
+ bfd_vma fptr = pe_get32 (dll, secptr1 + 20, &fail);
- bfd_seek (dll, secptr1, SEEK_SET);
- bfd_read (sname, 8, dll);
+ if (fail
+ || bfd_seek (dll, secptr1, SEEK_SET) != 0
+ || bfd_read (sname, 8, dll) != 8)
+ goto notdll;
if (vaddr <= export_rva && vaddr + vsize > export_rva)
{
for (i = 0; i < nsections; i++)
{
bfd_vma secptr1 = secptr + 40 * i;
- bfd_vma vsize = pe_get32 (dll, secptr1 + 8);
- bfd_vma vaddr = pe_get32 (dll, secptr1 + 12);
- bfd_vma flags = pe_get32 (dll, secptr1 + 36);
+ bfd_vma vsize = pe_get32 (dll, secptr1 + 8, &fail);
+ bfd_vma vaddr = pe_get32 (dll, secptr1 + 12, &fail);
+ bfd_vma flags = pe_get32 (dll, secptr1 + 36, &fail);
char sec_name[9];
sec_name[8] = '\0';
- bfd_seek (dll, secptr1 + 0, SEEK_SET);
- bfd_read (sec_name, 8, dll);
+ if (fail
+ || bfd_seek (dll, secptr1 + 0, SEEK_SET) != 0
+ || bfd_read (sec_name, 8, dll) != 8)
+ goto notdll;
if (strcmp(sec_name,".data") == 0)
{
}
expdata = xmalloc (export_size);
- bfd_seek (dll, expptr, SEEK_SET);
- bfd_read (expdata, export_size, dll);
+ if (bfd_seek (dll, expptr, SEEK_SET) != 0
+ || bfd_read (expdata, export_size, dll) != export_size)
+ goto notdll;
erva = (char *) expdata - export_rva;
if (pe_def_file == 0)