From: Ivan Maidanski Date: Sat, 16 Jun 2012 08:54:36 +0000 (+0400) Subject: test_cpp: Fix WinMain to prevent SEGV if zero arguments passed (MinGW) X-Git-Tag: gc7_2d~1^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e15af550c0301c0cb78ff00a46097542da2f15f;p=gc test_cpp: Fix WinMain to prevent SEGV if zero arguments passed (MinGW) * tests/test_cpp.cc (WinMain): Prevent SEGV in strtok() by checking "cmd" WinMain argument for NULL (in that case "argc" local variable is set to 0). --- diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index d463b345..2d2c3cf8 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -193,10 +193,11 @@ void* Undisguise( GC_word i ) { int APIENTRY WinMain( HINSTANCE instance, HINSTANCE prev, LPSTR cmd, int cmdShow ) { - int argc; + int argc = 0; char* argv[ 3 ]; - for (argc = 1; argc < (int)(sizeof(argv) / sizeof(argv[0])); argc++) { + if (cmd != 0) + for (argc = 1; argc < (int)(sizeof(argv) / sizeof(argv[0])); argc++) { argv[ argc ] = strtok( argc == 1 ? cmd : 0, " \t" ); if (0 == argv[ argc ]) break;} #elif defined(MACOS)