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_4_0~271 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7fdbdb9c409b6bf4ee3195c55fb514cf788b3c6;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 5197b0e4..f3340dbd 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -195,10 +195,11 @@ void* Undisguise( GC_word i ) { int APIENTRY WinMain( HINSTANCE instance ATTR_UNUSED, HINSTANCE prev ATTR_UNUSED, LPSTR cmd, int cmdShow ATTR_UNUSED ) { - 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)