Thread View: gnu.g++.bug
1 messages
1 total messages
Started by "Douglas C. Schmidt"
Sun, 27 Nov 1988 22:28
bugs in SLList.cc.proto
Author: "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()
{
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads