shithub: mc

Download patch

ref: 6e9c17391b5f1cc81904d622efccff55519be6d9
parent: a87c06a2b53bbaae033b37327c7e3db0495f23e4
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 23 18:13:04 EST 2016

Check slice bounds when slicing.

--- a/6/simp.c
+++ b/6/simp.c
@@ -701,7 +701,7 @@
 	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 @@
 	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 @@
 	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 @@
 		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);
 	}
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -9,7 +9,7 @@
 _LIBPATHS=$(addprefix -l, $(patsubst lib%.a,%,$(notdir $(DEPS)))) $(_PCLIBS)
 
 # yeah, I should probably remove -Werror, but it's nice for developing alone.
-CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-array-bounds -g -O2
+CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-array-bounds -g -O0
 CFLAGS += -MMD -MP -MF .deps/$(subst /,-,$*).d
 
 LIB ?= $(INSTLIB)