Fixed bug 1082 - Crash on startup when using empty command-line argument. SDL-1.2
authorSam Lantinga
Fri, 30 Dec 2011 06:54:58 -0500
branchSDL-1.2
changeset 612919c7412a6345
parent 6127 73a1a4c35259
child 6130 987c365cc7bf
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=<value optimized out>, argv=0x0)
at ./src/main/win32/SDL_win32_main.c:100
100 while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) {
(gdb) bt
#0 0x0047b2ea in ParseCommandLine (cmdline=<value optimized out>, 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.
src/main/win32/SDL_win32_main.c
     1.1 --- a/src/main/win32/SDL_win32_main.c	Fri Dec 30 06:41:12 2011 -0500
     1.2 +++ b/src/main/win32/SDL_win32_main.c	Fri Dec 30 06:54:58 2011 -0500
     1.3 @@ -98,7 +98,7 @@
     1.4  				++argc;
     1.5  			}
     1.6  			/* Skip over word */
     1.7 -			while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) {
     1.8 +			while ( *bufp && ( *bufp != '"' || (lastp && *lastp == '\\') ) ) {
     1.9  				lastp = bufp;
    1.10  				++bufp;
    1.11  			}