summaryrefslogtreecommitdiff
path: root/nasmlib
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-02-25 21:02:18 -0800
committerH. Peter Anvin <hpa@zytor.com>2019-02-25 21:02:18 -0800
commit437e0ffa01505d173a8b9cfe2decf74f2e9795a5 (patch)
treeaa2456e50fd0e157029ee1ad32e4be856d29b01e /nasmlib
parentefee3ea312358c16190ca5923c495ad8dc9a2547 (diff)
downloadnasm-437e0ffa01505d173a8b9cfe2decf74f2e9795a5.tar.gz
SAA: allow seeking beyond the end of the array
If putting the file pointer past the end of the array, expand the array with zeroes. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'nasmlib')
-rw-r--r--nasmlib/saa.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/nasmlib/saa.c b/nasmlib/saa.c
index fe7741a4..dcc2c019 100644
--- a/nasmlib/saa.c
+++ b/nasmlib/saa.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2017 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -262,9 +262,12 @@ void saa_fread(struct SAA *s, size_t posn, void *data, size_t len)
void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
{
size_t ix;
+ size_t padding = 0;
- /* Seek beyond the end of the existing array not supported */
- nasm_assert(posn <= s->datalen);
+ if (posn > s->datalen) {
+ padding = posn - s->datalen;
+ posn = s->datalen;
+ }
if (likely(s->blk_len == SAA_BLKLEN)) {
ix = posn >> SAA_BLKSHIFT;
@@ -281,6 +284,9 @@ void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
s->wblk--;
}
+ if (padding)
+ saa_wbytes(s, NULL, padding);
+
saa_wbytes(s, data, len);
}