aboutsummaryrefslogtreecommitdiff
path: root/bfd/libbfd.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2000-07-12 18:29:55 +0000
committerDJ Delorie <dj@redhat.com>2000-07-12 18:29:55 +0000
commite67f03db5baec45164b177cc6396b367fa6b15ff (patch)
tree0fe10ec7efbf9acd17768652f1bb14b39e4cf5da /bfd/libbfd.c
parent7f7888218f38ff55bb5a4879e2cc4bd3bdaf7f51 (diff)
downloadgdb-e67f03db5baec45164b177cc6396b367fa6b15ff.zip
gdb-e67f03db5baec45164b177cc6396b367fa6b15ff.tar.gz
gdb-e67f03db5baec45164b177cc6396b367fa6b15ff.tar.bz2
* libbfd.c (bfd_seek): fix 'seek beyond EOF' error when writing
out a structure that is BFD_IN_MEMORY.
Diffstat (limited to 'bfd/libbfd.c')
-rw-r--r--bfd/libbfd.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 1bc0f33..2e9c6c2 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -691,11 +691,31 @@ bfd_seek (abfd, position, direction)
if ((bfd_size_type) abfd->where > bim->size)
{
- abfd->where = bim->size;
- bfd_set_error (bfd_error_file_truncated);
- return -1;
- }
-
+ if ((abfd->direction == write_direction) ||
+ (abfd->direction == both_direction))
+ {
+ long newsize, oldsize = (bim->size + 127) & ~127;
+ bim->size = abfd->where;
+ /* Round up to cut down on memory fragmentation */
+ newsize = (bim->size + 127) & ~127;
+ if (newsize > oldsize)
+ {
+ bim->buffer = bfd_realloc (bim->buffer, newsize);
+ if (bim->buffer == 0)
+ {
+ bim->size = 0;
+ bfd_set_error (bfd_error_no_memory);
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ abfd->where = bim->size;
+ bfd_set_error (bfd_error_file_truncated);
+ return -1;
+ }
+ }
return 0;
}