]> granicus.if.org Git - gc/commitdiff
test_cpp: Fix WinMain to prevent SEGV if zero arguments passed (MinGW)
authorIvan Maidanski <ivmai@mail.ru>
Sat, 16 Jun 2012 08:54:36 +0000 (12:54 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 16 Jun 2012 08:54:36 +0000 (12:54 +0400)
* 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).

tests/test_cpp.cc

index 5197b0e457632bc3e6cdf724866e63f1dd357a29..f3340dbd914be2400e7008348b3621affe09af1e 100644 (file)
@@ -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)