commit e661eb2c41179d33b9ed3ad9d9626a3c5096f6d0
parent 917811557f5bc72a128b8d9f104a0774b34ea3b2
Author: Pierre Curto <pierre.curto@gmail.com>
Date: Sun, 14 Aug 2022 13:02:25 +0200
harec: fix slice OOB checks when start > end at runtime
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -2003,10 +2003,13 @@ gen_expr_delete(struct gen_context *ctx, const struct expression *expr)
struct qbe_value start_oob = mkqtmp(ctx, &qbe_word, ".%d");
struct qbe_value end_oob = mkqtmp(ctx, &qbe_word, ".%d");
+ struct qbe_value startend_oob = mkqtmp(ctx, &qbe_word, ".%d");
struct qbe_value valid = mkqtmp(ctx, &qbe_word, ".%d");
pushi(ctx->current, &start_oob, Q_CULEL, &qstart, &qlen, NULL);
pushi(ctx->current, &end_oob, Q_CULEL, &qend, &qlen, NULL);
pushi(ctx->current, &valid, Q_AND, &start_oob, &end_oob, NULL);
+ pushi(ctx->current, &startend_oob, Q_CULEL, &qstart, &qend, NULL);
+ pushi(ctx->current, &valid, Q_AND, &valid, &startend_oob, NULL);
struct qbe_statement linvalid, lvalid;
struct qbe_value binvalid = mklabel(ctx, &linvalid, ".%d");
@@ -2869,10 +2872,13 @@ gen_expr_slice_at(struct gen_context *ctx,
if (check_bounds) {
struct qbe_value start_oob = mkqtmp(ctx, &qbe_word, ".%d");
struct qbe_value end_oob = mkqtmp(ctx, &qbe_word, ".%d");
+ struct qbe_value startend_oob = mkqtmp(ctx, &qbe_word, ".%d");
struct qbe_value valid = mkqtmp(ctx, &qbe_word, ".%d");
pushi(ctx->current, &start_oob, Q_CULEL, &qstart, &qlength, NULL);
pushi(ctx->current, &end_oob, Q_CULEL, &qend, &qlength, NULL);
pushi(ctx->current, &valid, Q_AND, &start_oob, &end_oob, NULL);
+ pushi(ctx->current, &startend_oob, Q_CULEL, &qstart, &qend, NULL);
+ pushi(ctx->current, &valid, Q_AND, &valid, &startend_oob, NULL);
struct qbe_statement linvalid, lvalid;
struct qbe_value binvalid = mklabel(ctx, &linvalid, ".%d");