ref: cd5a0e5dbf567454d207e7ae7d22626e0c0845be
parent: 06e47267dd16d369450f94d5a1e29d29b94be511
author: Michael Forney <mforney@mforney.org>
date: Wed Feb 15 18:55:31 EST 2017
Avoid accessing beyond end of string When bp == lim, we should not dereference bp since it lies beyond the allocated memory.
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -317,7 +317,7 @@
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 @@
fprintf(outfp,
"\t#%c%02X\n",
chartype->letter, (*bp++) & 0xFF);
- } while (!isprint(*bp) && bp < lim);
+ } while (bp < lim && !isprint(*bp));
}
}