be-more-careful-about-references-when-adding-and-deleting-callbacks-20011001
authorDerrick Brashear <shadow@dementia.org>
Mon, 1 Oct 2001 18:51:41 +0000 (18:51 +0000)
committerDerrick Brashear <shadow@dementia.org>
Mon, 1 Oct 2001 18:51:41 +0000 (18:51 +0000)
perhaps too careful. to fix potential crash in TDel and TAdd

====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================

remove extra ) which snuck in

src/viced/callback.c

index 0d943aa..78ea701 100644 (file)
@@ -358,7 +358,12 @@ static TAdd(cb, thead)
 
        cb->tprev = thp->tprev;
        cb->tnext = *thead;
-       thp->tprev = (itocb(thp->tprev)->tnext = cbtoi(cb));
+       if (thp) {
+         if (thp->tprev) 
+           thp->tprev = (itocb(thp->tprev)->tnext = cbtoi(cb));
+         else 
+           thp->tprev = cbtoi(cb);
+       }
     }
     cb->thead = ttoi(thead);
 
@@ -374,8 +379,10 @@ static TDel(cb)
 
     if (*thead == cbtoi(cb))
        *thead = (*thead == cb->tnext? 0: cb->tnext);
-    itocb(cb->tprev)->tnext = cb->tnext;
-    itocb(cb->tnext)->tprev = cb->tprev;
+    if (itocb(cb->tprev)) 
+      itocb(cb->tprev)->tnext = cb->tnext;
+    if (itocb(cb->tnext)) 
+      itocb(cb->tnext)->tprev = cb->tprev;
 
 } /*TDel*/