From f27bf8110df4770d0ab6b15134cb7ecbafa9a201 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 30 Dec 2011 06:54:58 -0500 Subject: [PATCH] Fixed bug 1082 - Crash on startup when using empty command-line argument. yrizoud@gmail.com 2010-12-01 07:34:48 PST Run a SDL program with "" as one of the command-line arguments: crash on startup. Program received signal SIGSEGV, Segmentation fault. 0x0047b2ea in ParseCommandLine (cmdline=, argv=0x0) at ./src/main/win32/SDL_win32_main.c:100 100 while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) { (gdb) bt #0 0x0047b2ea in ParseCommandLine (cmdline=, argv=0x0) at ./src/main/win32/SDL_win32_main.c:100 #1 0x0047b5bb in WinMain@16 (hInst=0x400000, hPrev=0x0, szCmdLine=0x81c530e0 "a \"\" b", sw=10) at ./src/main/win32/SDL_win32_main.c:374 #2 0x0047af28 in main () --- The problem is that on Windows when you make a shortcut, and want it to accept drag-and-dropped files, the good way to make it work work with files that have spaces in their names or paths is make this argument "%1" (with the surrounding quotes). But then when you run it without dropping a file into it, it's resolved as "", and triggers this bug. --HG-- branch : SDL-1.2 --- src/main/win32/SDL_win32_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/win32/SDL_win32_main.c b/src/main/win32/SDL_win32_main.c index 803011ac9..672b48c12 100644 --- a/src/main/win32/SDL_win32_main.c +++ b/src/main/win32/SDL_win32_main.c @@ -98,7 +98,7 @@ static int ParseCommandLine(char *cmdline, char **argv) ++argc; } /* Skip over word */ - while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) { + while ( *bufp && ( *bufp != '"' || (lastp && *lastp == '\\') ) ) { lastp = bufp; ++bufp; }