tags:

views:

262

answers:

4

I have a MSVC 6.o workspace, which has all C code.
The code is being run without any optimization switch i.e with option O0, and in debug mode. This code is obtained from some 3rd party. It executes desirable as it is.

But when I add some printf statements in certain functions for debugging, and then execute the code, it crashes.

I suspect it to be some kind of code/data overflow across a memory-page/memory-segment or something alike. But the code does not have any memory map specifier, or linker command file mentioning the segments/memory map etc.

How do I narrow down the cause, and the fix for this quirky issue?

+1  A: 

On Linux, I like valgrind. Here is a Stack Overflow thread for valgrind-like tools on Windows.

Manuel
A: 

Use string.getbuffer while printing cstring objects in printf. There could be an issue for wide char and normal string. printf("%s",str.Getbuffer()); str.ReleaseBuffer(); Cheers, Atul.

Atul
+1  A: 

You could try to determine where the crash happens, by looking at the stack trace in Visual Studio. You should be able to see what is the sequence of function calls that eventually leads to the crash, and this may give you a hint as to what's wrong.

It is also possible that the printf() alone causes the crash. A possible cause - but not too likely on Windows - is a too-small stack that is being overflown by the call to printf().

Hexagon
A: 

In general when trying to deal with a crash, your first port of call should be the debugger.

Used correctly, this will enable you to narrow down your problem to a specific line of code and, hopefully, give you a view of the runtime memory at the moment of the crash. This will allow you to see the immediate cause of the crash.

Captain Lepton