summaryrefslogtreecommitdiff
path: root/6/simp.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-23 23:13:04 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-23 23:13:04 -0800
commit6e9c17391b5f1cc81904d622efccff55519be6d9 (patch)
treef857f7f73e3a5755dd5c1de2d8a7694ffe4b0255 /6/simp.c
parenta87c06a2b53bbaae033b37327c7e3db0495f23e4 (diff)
downloadmc-6e9c17391b5f1cc81904d622efccff55519be6d9.tar.gz
Check slice bounds when slicing.
Diffstat (limited to '6/simp.c')
-rw-r--r--6/simp.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/6/simp.c b/6/simp.c
index 23cb904..dbd96b8 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -701,7 +701,7 @@ static Node *membaddr(Simp *s, Node *n)
return r;
}
-static void checkidx(Simp *s, Node *len, Node *idx)
+static void checkidx(Simp *s, Op op, Node *len, Node *idx)
{
Node *cmp, *die;
Node *ok, *fail;
@@ -709,7 +709,7 @@ static void checkidx(Simp *s, Node *len, Node *idx)
if (!len)
return;
/* create expressions */
- cmp = mkexpr(idx->loc, Olt, ptrsized(s, idx), ptrsized(s, len), NULL);
+ cmp = mkexpr(idx->loc, op, ptrsized(s, idx), ptrsized(s, len), NULL);
cmp->expr.type = mktype(len->loc, Tybool);
ok = genlbl(len->loc);
fail = genlbl(len->loc);
@@ -744,7 +744,7 @@ static Node *idxaddr(Simp *s, Node *seq, Node *idx)
assert(t->expr.type->type == Typtr);
u = rval(s, idx, NULL);
u = ptrsized(s, u);
- checkidx(s, w, u);
+ checkidx(s, Olt, w, u);
sz = tysize(ty);
v = mul(u, disp(seq->loc, sz));
r = add(t, v);
@@ -969,6 +969,7 @@ static Node *simpslice(Simp *s, Node *n, Node *dst)
stbase = set(simpcast(s, t, mktyptr(t->loc, tyintptr)), base);
sz = addk(simpcast(s, t, mktyptr(t->loc, tyintptr)), Ptrsz);
} else {
+ checkidx(s, Ole, seqlen(s, seq, tyword), end);
stbase = set(deref(addr(s, t, tyintptr), NULL), base);
sz = addk(addr(s, t, tyintptr), Ptrsz);
}