Path: utzoo!telly!ddsw1!lll-winken!killer!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.edu
From: schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: bugs in SLList.cc.proto
Message-ID: <8811271428.aa23352@PARIS.ICS.UCI.EDU>
Date: 27 Nov 88 22:28:44 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 83


Hi,

   There are several rather devious bugs in the libg++ SLList.cc.proto
file.  The patches below fix those that I've found so far.  The major
problem is that the assignment operator and the copy in initialization
operation fail to work correctly when a list of length 1 is copied,
initialized, or passed by value to a function.  My fix works
correctly, and I'll leave the aesthetic recoding to Doug Lea ;-).

Doug Schmidt

----------------------------------------

*** SLList.cc.proto.old	Sun Nov 27 14:21:48 1988
--- SLList.cc.proto	Sun Nov 27 14:22:58 1988
***************
*** 56,61 ****
--- 56,65 ----
      SLListNode* p = a.last->tl;
      SLListNode* h = new SLListNode(p->hd);
      last = h;
+     if ( a.last == p ) { // performs correctly for lists of length 1
+        last->tl = last;
+        return;
+     }   
      p = p->tl;
      for (;;)
      {
***************
*** 73,79 ****
    }
  }
  
! inline SLList& SLList::operator = (SLList& a)
  {
    if (last == a.last)
      return *this;
--- 77,83 ----
    }
  }
  
! SLList& SLList::operator = (SLList& a)
  {
    if (last == a.last)
      return *this;
***************
*** 85,90 ****
--- 89,98 ----
        SLListNode* p = a.last->tl;
        SLListNode* h = new SLListNode(p->hd);
        last = h;
+       if ( a.last == p ) {
+          last->tl = last;
+          return;
+       }   
        p = p->tl;
        for (;;)
        {
***************
*** 182,187 ****
--- 190,211 ----
    return res;
  }
  
+ int SLList::remove_front(& x)
+ {
+   if (last == 0)
+     return 0;
+   else
+   {
+     SLListNode* t = last->tl;
+     x = t->hd;
+     if (t == last)
+       last = 0;
+     else
+       last->tl = t->tl;
+     delete t;
+     return 1;
+   }
+ }
  
  void SLList::del_front()
  {