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.
This commit is contained in:
Daniel Eklöf 2021-01-03 16:18:42 +01:00
parent 4849e8f874
commit 07078da0f0
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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);