Read from new, not old, buffer after realloc.

This got caught by MALLOC_OPTIONS=S in OpenBSD.  The B compiler filled
the buffer while compiling hilo.b.  Then realloc moved the buffer and
unmapped the old buffer.  The compiler tried to read the old buffer
and segfaulted.
This commit is contained in:
George Koehler 2018-03-08 12:04:02 -05:00
parent 0720671f7a
commit 860df1b067

View file

@ -99,20 +99,19 @@ C_out_parts(pp)
} }
else { else {
/* copy the chunk to output */ /* copy the chunk to output */
#ifdef INCORE
register char *s = C_BASE + pp->pp_begin;
char *se = C_BASE + pp->pp_end;
while (s < se) {
put(*s++);
}
#else
register long b = pp->pp_begin; register long b = pp->pp_begin;
while (b < pp->pp_end) { while (b < pp->pp_end) {
#ifdef INCORE
/* C_BASE is not constant, put() may
move C_BASE, so each iteration of
this loop must read C_BASE again.
*/
put(C_BASE[b++]);
#else
put(getbyte(b++)); put(getbyte(b++));
}
#endif #endif
}
} }
prev = pp; prev = pp;
pp = pp->pp_next; pp = pp->pp_next;