wcc: loop-label stack guards its depth loudly, both stages
wwstage's unguarded loop-label push wrote out of bounds at depth 17 (compiler-heap corruption); cstage guarded but emitted a wrong break target. Loud cap error at the limit, both stages, agreeing wording.
This commit is contained in:
@@ -38835,6 +38835,14 @@ fn cgfor(c: *cgen, n: *node) void = {
|
||||
emitline("\tJE\t"); emitline(naturall); emitline("\n");
|
||||
};
|
||||
|
||||
// #42: bound the push. The buffers are sized exactly LOOP_MAX, so an
|
||||
// unguarded push at nesting depth LOOP_MAX+1 is an OOB heap write;
|
||||
// fail loud at the cap, both stages (cgen.c twin fatals too).
|
||||
if (c.looptop >= LOOP_MAX) {
|
||||
let msg: str = "cgen: loop nesting too deep\n";
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
c.loopendbuf[c.looptop] = endl;
|
||||
c.loopcontbuf[c.looptop] = conttgt;
|
||||
c.looptop += 1;
|
||||
@@ -39714,6 +39722,14 @@ fn cgforrange(c: *cgen, n: *node) void = {
|
||||
// the value that triggered continue. Dedicated `rpost` label.
|
||||
let rpost: str = mklabel(c, "rpost");
|
||||
|
||||
// #42: bound the push. The buffers are sized exactly LOOP_MAX, so an
|
||||
// unguarded push at nesting depth LOOP_MAX+1 is an OOB heap write;
|
||||
// fail loud at the cap, both stages (cgen.c twin fatals too).
|
||||
if (c.looptop >= LOOP_MAX) {
|
||||
let msg: str = "cgen: loop nesting too deep\n";
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
c.loopcontbuf[c.looptop] = rpost;
|
||||
c.loopendbuf[c.looptop] = endl;
|
||||
c.looptop += 1;
|
||||
|
||||
Reference in New Issue
Block a user