This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Very simple bug, setting pointer to a value in an if statement.


OK, this bug was brought on by a mistake I made while writing a removenode function for a linked list class that I'm making in C++. It's easy to trigger and, while a program written correctly won't ever experience a defect from it, it does cause problems while debugging. I'm using gcc 4.3.0.

Here's the code that triggers the bug:

node<T> *current = FirstNode;
node<T> *previous = current;
if ( current = 0 )
return 0;
else
{
cout << FirstNode << ":" << current << ":" << previous << "\n";
... snip ...



You'll notice the mistake I made in the if statement where I didn't use '==' and accidentally use '='. For some reason the function kept returning 0 and I added the output to check the locations of the different nodes. I noticed that while FirstNode and previous were set to the same location, current was at 0, and since previous had been set to current's location, somehow current was getting set to 0. I looked at the if statement and I noticed my mistake but was puzzled as to why the compiler didn't return any error messages. I presume that it's a bug, however there may be some special property of pointers that I'm not aware of, I'm really not sure, my experience with C++ is limited.


The command I used to compile this was very simple.
g++ lltest.cpp -o lltest

If there's anymore information you need, please tell me, or if this isn't really a bug I'd appreciate knowing that as well.

Thank you,

Ted



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]