aboutsummaryrefslogtreecommitdiff
path: root/extract.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-03 15:18:42 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-04 18:48:44 +0000
commit07078da0f07dfd410398ec9c816b2d7d888f2d38 (patch)
treefd362842f1dee95f53350b13b04f596016caa282 /extract.c
parentselection: update: line-wraps are ok while moving pivot start/end point (diff)
extract: finish: fix bad assertion - ‘idx’ may be equal to ‘size’
‘idx’ is where _new_ data should be pushed into the buffer. Thus it is perfectly valid for it to be equal to ‘size’ - it just means we need to allocate more space before pushing data to it.
Diffstat (limited to 'extract.c')
-rw-r--r--extract.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/extract.c b/extract.c
index 7b5da229..d6214f70 100644
--- a/extract.c
+++ b/extract.c
@@ -72,11 +72,14 @@ extract_finish(struct extraction_context *ctx, char **text, size_t *len)
ctx->buf[ctx->idx] = L'\0';
} else {
assert(ctx->idx > 0);
- assert(ctx->idx < ctx->size);
+ assert(ctx->idx <= ctx->size);
if (ctx->buf[ctx->idx - 1] == L'\n')
ctx->buf[ctx->idx - 1] = L'\0';
- else
+ else {
+ if (!ensure_size(ctx, 1))
+ goto out;
ctx->buf[ctx->idx] = L'\0';
+ }
}
size_t _len = wcstombs(NULL, ctx->buf, 0);