|
Boost Users : |
Subject: Re: [Boost-users] Unordered map copy segfaults! (STL map does not)
From: MeMooMeM (mbelgin_at_[hidden])
Date: 2009-08-21 18:18:45
MeMooMeM wrote:
>
>
> Mathias Gaunard-2 wrote:
>>
>> You should write a proper testcase and provide your platform, so that
>> people have a chance to reproduce your results.
>>
>
> That's right. I prepared a toy code as you suggested, but it works just
> fine (?!). When I use the same structure inside my code, it segfaults. It
> is most probably due to some messed up memory section. Still it is strange
> that I get no segfaults (also no detected errors by valgrind) using STL's
> map...
>
> Everyone, please ignore this post until I find a proper way to demonstrate
> the problem.
>
> Thanks!
>
OK, mystery is solved. Here's what happened, in case someone else has this
problem:
I was *not* using the standard for loop, as in:
for (Map_t::iterator it = somemap.begin(); it != somemap.end(); it++)
because I was erasing elements from the map, which is known to mess things
up if a for loop is being used. Instead, I was using a while loop and
incrementing the iterator in a more controlled way:
somemap.erase(it++);
which erases the element but still returns correclty incremented iterator.
However forgot to check for the case: (it++ == somemap.end()) in the while
loop, hence the segmentation faults.
Thanks again!
-- View this message in context: http://www.nabble.com/Unordered-map-copy-segfaults%21-%28STL-map-does-not%29-tp25034074p25088176.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net