while(myVector.size() > 0)
{
int sz = myVector.size(); //This was for debugging
//Do a bunch of stuff and push back the vector a number of times
}
sz is not changed by ANYTHING else in the program, and I have been getting a segfault in a VERY rare occurance later on in the program. When I inserted a breakpoint after the above code, I found out that,
sz = -1
How is this possible? Am I missing something?
Could it be because I may have tried to push back the vector past 0? But then why did the while loop even execute? I'm puzzled!
size() returns an unsigned value so it can't return -1. size() probably return a very large value and that can't fit in the range of the signed int, so you get an overflow and the result is -1. This could be because you have added a huge number of elements to the vector (unlikely) or that you have used something like pop_back when the size was 0.