commit 1dfb93dc4b91b4c3e5186757965a42595e142b9a
parent 887f13a8d9d9abdd6a14d6815f0a6a7d3f94073f
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 15 Feb 2017 23:55:31 -0800
Avoid accessing beyond end of string
When bp == lim, we should not dereference bp since it lies beyond the
allocated memory.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cc1/code.c b/cc1/code.c
@@ -317,7 +317,7 @@ emitstring(Symbol *sym, Type *tp)
lim = &sym->u.s[tp->n.elem];
while (bp < lim) {
s = bp;
- while (isprint(*bp) && bp < lim)
+ while (bp < lim && isprint(*bp))
++bp;
if ((n = bp - s) > 1)
fprintf(outfp, "\t#\"%.*s\n", n, s);
@@ -329,7 +329,7 @@ emitstring(Symbol *sym, Type *tp)
fprintf(outfp,
"\t#%c%02X\n",
chartype->letter, (*bp++) & 0xFF);
- } while (!isprint(*bp) && bp < lim);
+ } while (bp < lim && !isprint(*bp));
}
}