Don't access stuff we have realloc()'ed using the old pointer.

This is a sample of a new class of malloc usage errors that the
Junk option to phkmalloc will expose.

Found by: phkmalloc.
This commit is contained in:
phk 1996-10-21 08:51:58 +00:00
parent 8fd01a136e
commit d225820440

View File

@ -275,7 +275,7 @@ slurp(F)
* join field.
*/
F->setcnt = 0;
for (lastlp = NULL;; ++F->setcnt, lastlp = lp) {
for (lastlp = NULL;; ++F->setcnt) {
/*
* If we're out of space to hold line structures, allocate
* more. Initialize the structure so that we know that this
@ -296,9 +296,10 @@ slurp(F)
* the two structures so that we don't lose space allocated to
* either structure. This could be avoided by doing another
* level of indirection, but it's probably okay as is.
* but it's probably okay as is.
*/
lp = &F->set[F->setcnt];
if (F->setcnt)
lastlp = &F->set[F->setcnt - 1];
if (F->pushbool) {
tmp = F->set[F->setcnt];
F->set[F->setcnt] = F->set[F->pushback];