summaryrefslogtreecommitdiff
path: root/bfd/section.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@bigpond.net.au>2001-09-18 09:57:26 +0000
committerAlan Modra <amodra@bigpond.net.au>2001-09-18 09:57:26 +0000
commit439c22790eb92fc38c0c4e91bc343ef8d0e55427 (patch)
treeeb49f3489bb7e104ca1c425d07d5d954ab03148f /bfd/section.c
parent8ff532ca9bf72656df68051c20729d9fdec919b9 (diff)
downloadgdb-439c22790eb92fc38c0c4e91bc343ef8d0e55427.tar.gz
Touches most files in bfd/, so likely will be blamed for everything..
o bfd_read and bfd_write lose an unnecessary param and become bfd_bread and bfd_bwrite. o bfd_*alloc now all take a bfd_size_type arg, and will error if size_t is too small. eg. 32 bit host, 64 bit bfd, verrry big files or bugs in linker scripts etc. o file_ptr becomes a bfd_signed_vma. Besides matching sizes with various other types involved in handling sections, this should make it easier for bfd to support a 64 bit off_t on 32 bit hosts that provide it. o I've made the H_GET_* and H_PUT_* macros (which invoke bfd_h_{get,put}_*) generally available. They now cast their args to bfd_vma and bfd_byte * as appropriate, which removes a swag of casts from the source. o Bug fixes to bfd_get8, aix386_core_vec, elf32_h8_relax_section, and aout-encap.c. o Zillions of formatting and -Wconversion fixes.
Diffstat (limited to 'bfd/section.c')
-rw-r--r--bfd/section.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/bfd/section.c b/bfd/section.c
index 78ab0cb4830..dc875bb66ef 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -689,7 +689,7 @@ bfd_get_unique_section_name (abfd, templat, count)
char *sname;
len = strlen (templat);
- sname = bfd_malloc (len + 8);
+ sname = bfd_malloc ((bfd_size_type) len + 8);
if (sname == NULL)
return NULL;
strcpy (sname, templat);
@@ -788,7 +788,7 @@ bfd_make_section_anyway (abfd, name)
sect = sect->next;
}
- newsect = (asection *) bfd_zalloc (abfd, sizeof (asection));
+ newsect = (asection *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asection));
if (newsect == NULL)
return NULL;
@@ -1013,12 +1013,9 @@ FUNCTION
bfd_set_section_contents
SYNOPSIS
- boolean bfd_set_section_contents
- (bfd *abfd,
- asection *section,
- PTR data,
- file_ptr offset,
- bfd_size_type count);
+ boolean bfd_set_section_contents (bfd *abfd, asection *section,
+ PTR data, file_ptr offset,
+ bfd_size_type count);
DESCRIPTION
Sets the contents of the section @var{section} in BFD
@@ -1059,17 +1056,15 @@ bfd_set_section_contents (abfd, section, location, offset, count)
return (false);
}
- if (offset < 0)
+ sz = bfd_get_section_size_now (abfd, section);
+ if ((bfd_size_type) offset > sz
+ || count > sz
+ || offset + count > sz
+ || count != (size_t) count)
{
- bad_val:
bfd_set_error (bfd_error_bad_value);
return false;
}
- sz = bfd_get_section_size_now (abfd, section);
- if ((bfd_size_type) offset > sz
- || count > sz
- || offset + count > sz)
- goto bad_val;
switch (abfd->direction)
{
@@ -1092,7 +1087,7 @@ bfd_set_section_contents (abfd, section, location, offset, count)
/* Record a copy of the data in memory if desired. */
if (section->contents
&& location != section->contents + offset)
- memcpy (section->contents + offset, location, count);
+ memcpy (section->contents + offset, location, (size_t) count);
if (BFD_SEND (abfd, _bfd_set_section_contents,
(abfd, section, location, offset, count)))
@@ -1109,9 +1104,9 @@ FUNCTION
bfd_get_section_contents
SYNOPSIS
- boolean bfd_get_section_contents
- (bfd *abfd, asection *section, PTR location,
- file_ptr offset, bfd_size_type count);
+ boolean bfd_get_section_contents (bfd *abfd, asection *section,
+ PTR location, file_ptr offset,
+ bfd_size_type count);
DESCRIPTION
Read data from @var{section} in BFD @var{abfd}
@@ -1138,21 +1133,21 @@ bfd_get_section_contents (abfd, section, location, offset, count)
if (section->flags & SEC_CONSTRUCTOR)
{
- memset (location, 0, (unsigned) count);
+ memset (location, 0, (size_t) count);
return true;
}
- if (offset < 0)
+ /* Even if reloc_done is true, this function reads unrelocated
+ contents, so we want the raw size. */
+ sz = section->_raw_size;
+ if ((bfd_size_type) offset > sz
+ || count > sz
+ || offset + count > sz
+ || count != (size_t) count)
{
- bad_val:
bfd_set_error (bfd_error_bad_value);
return false;
}
- /* Even if reloc_done is true, this function reads unrelocated
- contents, so we want the raw size. */
- sz = section->_raw_size;
- if ((bfd_size_type) offset > sz || count > sz || offset + count > sz)
- goto bad_val;
if (count == 0)
/* Don't bother. */
@@ -1160,7 +1155,7 @@ bfd_get_section_contents (abfd, section, location, offset, count)
if ((section->flags & SEC_HAS_CONTENTS) == 0)
{
- memset (location, 0, (unsigned) count);
+ memset (location, 0, (size_t) count);
return true;
}
@@ -1179,7 +1174,8 @@ FUNCTION
bfd_copy_private_section_data
SYNOPSIS
- boolean bfd_copy_private_section_data(bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
+ boolean bfd_copy_private_section_data (bfd *ibfd, asection *isec,
+ bfd *obfd, asection *osec);
DESCRIPTION
Copy private section information from @var{isec} in the BFD