[gnu.g++.bug] bugs in SLList.cc.proto

schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (11/28/88)

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 ----
      <T>SLListNode* p = a.last->tl;
      <T>SLListNode* h = new <T>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 <T>SLList& <T>SLList::operator = (<T>SLList& a)
  {
    if (last == a.last)
      return *this;
--- 77,83 ----
    }
  }
  
! <T>SLList& <T>SLList::operator = (<T>SLList& a)
  {
    if (last == a.last)
      return *this;
***************
*** 85,90 ****
--- 89,98 ----
        <T>SLListNode* p = a.last->tl;
        <T>SLListNode* h = new <T>SLListNode(p->hd);
        last = h;
+       if ( a.last == p ) {
+          last->tl = last;
+          return;
+       }   
        p = p->tl;
        for (;;)
        {
***************
*** 182,187 ****
--- 190,211 ----
    return res;
  }
  
+ int <T>SLList::remove_front(<T>& x)
+ {
+   if (last == 0)
+     return 0;
+   else
+   {
+     <T>SLListNode* t = last->tl;
+     x = t->hd;
+     if (t == last)
+       last = 0;
+     else
+       last->tl = t->tl;
+     delete t;
+     return 1;
+   }
+ }
  
  void <T>SLList::del_front()
  {