Boost logo

Boost Users :

Subject: Re: [Boost-users] Strange issue with boost::date_time
From: Jared Lee Richardson (jaredr26_at_[hidden])
Date: 2009-04-15 16:27:09


On Wed, Apr 15, 2009 at 10:25 AM, Igor R <boost.lists_at_[hidden]> wrote:
>> Bad if the vector resizes and moves them elsewhere
>
> std::vector guarantees that its elements are stored in a contiguous
> memory block, so it definitely moves the data on resize and
> invalidates iterators.
>
>> I changed from /MT to /MD compiles as per Neil's suggestion and the crash moved to a slightly later new call.
>
> This strengthens the assumption that you've got a heap corruption.

Hmm, wow, ok I think you were right, but it was really subtle. :(

//String is read in from file, delimited.
char string[32];
File.getline(string, 32, '"');

int Length = strlen(string); // <-- Does not include Null character!
char* Name = new char[Length]; // <-- One char too small
strcpy(Name, string); // <-- Corrupted 1 byte after Name's end.

And I guess the reason it didn't crash when an external app was
hooking / starting my program was because it just randomly shifted the
heap?

Fixing the above(and using strcpy_s) fixed the crash in my smaller
subset of the program, but it still crashes later. Probably because
of how I was mis-using vectors.

Thanks for the help everyone. My stupidity. Weird that it only
happened when run standalone though.

Jared


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