commit e094dece2c7113a1eab85fc45f7a6a46d5d03659
parent 486a8e57b0532e507688e012bc33258e6edb4d40
Author: Alexey Yerin <yyp@disroot.org>
Date: Mon, 23 Aug 2021 19:45:04 +0300
check: fix string length calculation
The resulting string length was not including the assertion string, only
its location, which resulted in incomplete messages.
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -418,14 +418,14 @@ check_expr_assert(struct context *ctx,
size_t n = snprintf(NULL, 0, "%s:%d:%d: ",
aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno);
size_t s_len = expr->assert.message->constant.string.len;
- char *s = xcalloc(1, s_len + n + 1);
+ char *s = xcalloc(1, n + s_len + 1);
snprintf(s, n + 1, "%s:%d:%d: ",
aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno);
memcpy(s+n, expr->assert.message->constant.string.value, s_len);
s[n + s_len] = '\0';
expr->assert.message->constant.string.value = s;
- expr->assert.message->constant.string.len = n;
+ expr->assert.message->constant.string.len = n + s_len;
} else {
int n = snprintf(NULL, 0, "Assertion failed: %s:%d:%d",
aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno);