Discussion:
crash while assigning std::list iterators
(too old to reply)
t***@gmail.com
2015-03-07 12:55:45 UTC
Permalink
Raw Message
Hello,

The following code crashes in Visual Studio 2010, but is ok with 2013. It is code which was stripped from a more complex example.
What am I doing wrong?

Thanks a lot!
Thomas


#include <list>

int main(int , char *[])
{
std::list<int> List;
std::list<int>::iterator I1, I2, I3;

List.push_back(1);
I2 = List.begin();
I1 = I2;
I1 = I3;
}
Barry Schwarz
2015-03-07 16:59:06 UTC
Permalink
Raw Message
Post by t***@gmail.com
Hello,
The following code crashes in Visual Studio 2010, but is ok with 2013. It is code which was stripped from a more complex example.
What am I doing wrong?
Thanks a lot!
Thomas
#include <list>
int main(int , char *[])
Of course your real code has parameter names.
Post by t***@gmail.com
{
std::list<int> List;
std::list<int>::iterator I1, I2, I3;
List.push_back(1);
I2 = List.begin();
I1 = I2;
I1 = I3;
The value of I3 is indeterminate. You attempt to evaluate that value
to assign it to I1. Evaluating an indeterminate pointer (iterators
are pointers under the covers) causes undefined behavior. A crash is
one of the most useful manifestations of undefined behavior.
Post by t***@gmail.com
}
--
Remove del for email
t***@gmail.com
2015-03-07 20:23:31 UTC
Permalink
Raw Message
On Sat, 7 Mar 2015 04:55:45 -0800 (PST), thomas.grund...
Post by t***@gmail.com
Hello,
The following code crashes in Visual Studio 2010, but is ok with 2013. It is code which was stripped from a more complex example.
What am I doing wrong?
Thanks a lot!
Thomas
#include <list>
int main(int , char *[])
Of course your real code has parameter names.
Sure it has ;-)
Post by t***@gmail.com
{
std::list<int> List;
std::list<int>::iterator I1, I2, I3;
List.push_back(1);
I2 = List.begin();
I1 = I2;
I1 = I3;
The value of I3 is indeterminate. You attempt to evaluate that value
to assign it to I1. Evaluating an indeterminate pointer (iterators
are pointers under the covers) causes undefined behavior. A crash is
one of the most useful manifestations of undefined behavior.
Post by t***@gmail.com
}
--
Remove del for email
Ah ok, got it.

Thanks a lot,
Thomas

Loading...