Article View: gnu.g++.bug
Article #1546bugs in SLList.cc.proto
From: "Douglas C. Schmidt"
Date: Sun, 27 Nov 1988 22:28
Date: Sun, 27 Nov 1988 22:28
84 lines
2351 bytes
2351 bytes
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()
{
Technical Details
Message-ID:
<8811271428.aa23352@PARIS.ICS.UCI.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!killer!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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