3

I had on old C++ project starting a Console-application.
With a breakpoint in main(int argc, char** argv) started program.exe -debug.
According to the debugger argc became 32 and the strings in argv had weird random-like values.
When execution continued access violation occurred, since the strings in argv pointed to invalid values.

What can be causing this?

leiflundgren
  • 2,876
  • 7
  • 35
  • 53
  • Did you print the value of `argc` within main to `stdout` to see if it also reported 32? – hmjd Nov 30 '11 at 16:08

1 Answers1

5

The linker had wrong Entry Point set.
For a normal console application this should be mainCRTStartup (the debugger shows __tmainCRTStartup).

Having an invalid entry point caused main to look at what "happended" to be in the stack.
Posting this since it was not trivial to find.

leiflundgren
  • 2,876
  • 7
  • 35
  • 53
  • Thanks for following up and posting this arcane bit of knowledge. – djdanlib Nov 30 '11 at 17:01
  • i doubt so. if the linker didn't find `__tmainCRTStartup` it will complain, but apparently it didn't and continue to link the project. i suspect that `char** argv` is the cause of the crash (a non writable buffer). try `char * argv[]`. – milevyo Feb 04 '16 at 01:01