We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1082

Summary: Crash on startup when using empty command-line argument.
Product: SDL Reporter: yrizoud
Component: mainAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: trivial    
Priority: P1 CC: jspradlin
Version: 1.2.14   
Hardware: x86   
OS: Windows (95/98/ME)   

Description yrizoud 2010-12-01 07:34:48 UTC
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.
Comment 1 Jen Spradlin 2011-04-12 20:07:06 UTC
Thank you for your bug report!

We're busy working on getting SDL 1.3 ready for a high quality release, and want to make sure as many things are fixed there as possible.
Could you check to see if your bug is resolved by the latest SDL 1.3 snapshot?
http://www.libsdl.org/tmp/SDL-1.3.zip

Thanks!
Comment 2 yrizoud 2011-04-14 14:55:17 UTC
Sorry I can't say for 1.3, can't get the full toolchain to build it.
The source for this part had almost no change.
However, I just noticed something important about this issue: It only occurs when running the SDL program using GDB or MSYS's shell! So it's only an annoyance for developers. So I lowered "importance" to trivial.
It's probably one of the side effects of such environment causes a different string for GetCommandLine(), especially a mix of / and \ like:
"D:\\Data\\C\\GFX2\\grafx2\\src/..\\bin\\grafx2.exe arg1 arg2"
Or if a space is present in path:
"\"D:\\Data\\C\\GFX2\\grafx2\\src/..\\bin\\test space\\grafx2.exe\" arg1 arg2"
Comment 3 Ryan C. Gordon 2011-12-30 01:25:43 UTC
Bumping priority on a few bugs that I would like examined more closely before 1.2.15 is finalized. This is not a promise that a bug will be fixed. We may close it with WONTFIX or WORKSFORME or something, but I just want to make sure attention is paid.

--ryan.
Comment 4 Sam Lantinga 2011-12-30 03:46:34 UTC
Oh, I see the problem here.  I'll have a fix shortly.
Comment 5 Sam Lantinga 2011-12-30 03:55:26 UTC
This is fixed, thanks!
http://hg.libsdl.org/SDL/rev/19c7412a6345