harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9468b525112da6a978c9ffad01127c01a7cd6e55
parent 97f98922642ae4307f9c0442be3155afcb874cad
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri,  1 Jan 2021 12:15:37 -0500

check: generate assertion message if applicable

Diffstat:
Msrc/check.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -110,12 +110,16 @@ check_expr_assert(struct context *ctx, expr->assert.message->result->storage == TYPE_STORAGE_STRING, "Assertion message must be string"); } else { + int n = snprintf(NULL, 0, "Assertion failed: %s:%d:%d", + aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno); + char *s = xcalloc(1, n + 1); + snprintf(s, n, "Assertion failed: %s:%d:%d", + aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno); + expr->assert.message->type = EXPR_CONSTANT; expr->assert.message->result = &builtin_type_const_str; - expr->assert.message->constant.string.value = - strdup("TODO: add filename and line number here"); - expr->assert.message->constant.string.len = - strlen(expr->assert.message->constant.string.value); + expr->assert.message->constant.string.value = s; + expr->assert.message->constant.string.len = n; } }