summaryrefslogtreecommitdiffstats
path: root/usr.bin/join
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1996-10-21 08:51:58 +0000
committerphk <phk@FreeBSD.org>1996-10-21 08:51:58 +0000
commitd225820440c2849687d9bd421a5132fc9df142f2 (patch)
tree2b586ffb84334821e867f69b5d40bbd9f49dc318 /usr.bin/join
parent8fd01a136e847689c60d19cd8d439b37c9a7b5a9 (diff)
downloadFreeBSD-src-d225820440c2849687d9bd421a5132fc9df142f2.zip
FreeBSD-src-d225820440c2849687d9bd421a5132fc9df142f2.tar.gz
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.
Diffstat (limited to 'usr.bin/join')
-rw-r--r--usr.bin/join/join.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/join/join.c b/usr.bin/join/join.c
index d717835..15d77ff 100644
--- a/usr.bin/join/join.c
+++ b/usr.bin/join/join.c
@@ -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];
OpenPOWER on IntegriCloud