summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-10-15 21:59:43 -0700
committerOri Bernstein <ori@eigenstate.org>2018-10-15 21:59:43 -0700
commitaeff53ae83c1b00f86934d85033d710f8826ba36 (patch)
tree6f089d885f68c596970e227101d25606b6d8990f /6
parentb17873ed4e6a14786758fd68290ef572b0b88f10 (diff)
downloadmc-aeff53ae83c1b00f86934d85033d710f8826ba36.tar.gz
Disallow negative array sizes. And do some cleanup.
Diffstat (limited to '6')
-rw-r--r--6/blob.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/6/blob.c b/6/blob.c
index 410acab..c78a6f2 100644
--- a/6/blob.c
+++ b/6/blob.c
@@ -99,17 +99,6 @@ blobfree(Blob *b)
free(b);
}
-static size_t
-getintlit(Node *n, char *failmsg)
-{
- if (exprop(n) != Olit)
- fatal(n, "%s", failmsg);
- n = n->expr.args[0];
- if (n->lit.littype != Lint)
- fatal(n, "%s", failmsg);
- return n->lit.intval;
-}
-
void
b(Blob *b, Blob *n)
{
@@ -188,7 +177,7 @@ static size_t
blobslice(Blob *seq, Htab *globls, Htab *strtab, Node *n)
{
Node *base, *lo, *hi;
- ssize_t loval, hival, sz;
+ vlong loval, hival, baseval, sz;
Blob *slbase;
char *lbl;
@@ -199,14 +188,18 @@ blobslice(Blob *seq, Htab *globls, Htab *strtab, Node *n)
/* by this point, all slicing operations should have had their base
* pulled out, and we should have vars with their pseudo-decls in their
* place */
- loval = getintlit(lo, "lower bound in slice is not constant literal");
- hival = getintlit(hi, "upper bound in slice is not constant literal");
+ if (!getintlit(lo, &loval))
+ fatal(lo, "lower bound in slice is not constant literal");
+ if (!getintlit(hi, &hival))
+ fatal(hi, "upper bound in slice is not constant literal");
if (exprop(base) == Ovar && base->expr.isconst) {
sz = tysize(tybase(exprtype(base))->sub[0]);
lbl = htget(globls, base);
slbase = mkblobref(lbl, loval*sz, 1);
} else if (exprop(base) == Olit || exprop(base) == Oarr) {
- slbase = mkblobi(Bti64, getintlit(base, "invalid base expr"));
+ if (!getintlit(base, &baseval))
+ fatal(base, "invalid base expr");
+ slbase = mkblobi(Bti64, baseval);
} else {
fatal(base, "slice base is not a constant value");
}