From 437e0ffa01505d173a8b9cfe2decf74f2e9795a5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 25 Feb 2019 21:02:18 -0800 Subject: [PATCH] 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 --- nasmlib/saa.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nasmlib/saa.c b/nasmlib/saa.c index fe7741a4a..dcc2c0196 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); }