diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-01-03 15:18:42 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-01-04 18:48:44 +0000 |
| commit | 07078da0f07dfd410398ec9c816b2d7d888f2d38 (patch) | |
| tree | fd362842f1dee95f53350b13b04f596016caa282 /extract.c | |
| parent | selection: 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.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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); |
