I’ve been tasked with porting an MFC Visual Studio 6 C++ app to VS2005 and have run into a baffling memory error. The program is quite large (1,000,000 lines) so this is turning into a needle in a haystack quandary.

The first indication of trouble currently comes from Boundschecker reporting a memory overrun during program instantiation. The code triggering the overrun is fine (an array of simple structures being initialized). If I move the code to a simple test project it executes flawlessly. So I have to assume that this is a symptom of an existing problem, rather than the problem itself.

Another frustrating thing is that _CrtCheckMemory( ) report no problems when called before or immediately after this line of code.

The code below is from the CTOR of an object owned by the App. It is not dynamically allocated. The element that is failing is definitely within the array bounds.

_ASSERTE(_CrtCheckMemory()); // ok
data[24][35].eventListIdx = 1; // boundschecker reports a memory write overrun
_ASSERTE(_CrtCheckMemory()); // still ok

Originally the object that contained this array was defined globally (instead of being owned by the App). The same behavior was noted except that it failed on an earlier element of the array).

If I comment out the offending code I simply get a memory error somewhere else later during instantiation. Eventually _CrtCheckMemory() will return an error, but this does me little good at that point.

At present I am baffled as to where to go from here. The program is huge and poorly encapsulated (so I can’t build it up module by module).

I would deeply appreciate any ideas or strategies from those who have seen this sort of thing themselves. I understand this isn’t much to go on, but I’m mainly looking for a place to start. Thankyou.