aboutsummaryrefslogtreecommitdiff
path: root/extract.c
diff options
context:
space:
mode:
Diffstat (limited to 'extract.c')
-rw-r--r--extract.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/extract.c b/extract.c
index 7b5da229..a6492716 100644
--- a/extract.c
+++ b/extract.c
@@ -69,14 +69,17 @@ extract_finish(struct extraction_context *ctx, char **text, size_t *len)
/* Selection of empty cells only */
if (!ensure_size(ctx, 1))
goto out;
- ctx->buf[ctx->idx] = L'\0';
+ 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
- ctx->buf[ctx->idx] = L'\0';
+ else {
+ if (!ensure_size(ctx, 1))
+ goto out;
+ ctx->buf[ctx->idx++] = L'\0';
+ }
}
size_t _len = wcstombs(NULL, ctx->buf, 0);