commit d5aee16e85da40db7f427cb8358697cf9f93236d
parent c2ce6392f471292486baa50e0e632226f716f990
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 28 Apr 2021 13:16:45 -0400
Fix slice capacity with undefined length array
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -2569,11 +2569,12 @@ gen_expr_slice(struct gen_context *ctx,
pushc(ctx->current, "store capacity");
pushi(ctx->current, &dest, Q_ADD, &dest, &temp, NULL);
- // XXX: Does this assert need to be enforced higher up the
- // stack?
- assert(otype->array.length != SIZE_UNDEFINED);
- constl(&temp, otype->array.length);
- pushi(ctx->current, &offset, Q_SUB, &temp, &offset, NULL);
+
+ if (otype->array.length != SIZE_UNDEFINED) {
+ constl(&temp, otype->array.length);
+ pushi(ctx->current, &offset, Q_SUB, &temp, &offset, NULL);
+ pushi(ctx->current, NULL, Q_STOREL, &offset, &dest, NULL);
+ }
pushi(ctx->current, NULL, Q_STOREL, &offset, &dest, NULL);
}
}