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:
Poul-Henning Kamp 1996-10-21 08:51:58 +00:00
parent db91faacb6
commit bf6570c4a5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=19069

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];