| Summary: | SDL_memset crashes on unaligned destinations [PATCH] | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Yuri K. Schlesner <yuriks> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | skaller |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 8 | ||
| Attachments: | Proposed patch. | ||
Looks like this is a bug of #2030. Sorry, didn't notice it while writing the report. I don't know if I should close this as a dupe, since I have a patch. (In reply to Yuri K. Schlesner from comment #0) > Is there a platform without memset available? To answer this question: there aren't any platforms we care about without memset(), but on Windows, we don't have any dependency on a C runtime at all (since it generally causes conflicts with people that want to use any of the several that Microsoft offers, or Cygwin's, Borland's, etc), so for the real basic pieces of the C runtime everyone expects, like memset, we offer simple implementations of our own. Checking patch now. --ryan. This patch is now https://hg.libsdl.org/SDL/rev/d21a3ff2b0d2 ... thanks! --ryan. |
Created attachment 1644 [details] Proposed patch. SDL_FillRect was crashing for me and I tracked this down to a bug/bad interaction with code generation in SDL_memset. GCC generates SSE unaligned store instructions for the Uint32 loop, causing crashes if the destination buffer isn't aligned on a 4-byte boundary. This affects the official 2.0.3 64-bit binaries for MinGW. (Note: if you compile your own SDL, it may have HAVE_MEMSET set, and will thus use the libc memset and you will not hit this bug. Manually comment out HAVE_MEMSET in SDL_config.h if that's the case.) I've attached a patch that fixes this by manually copying the first bytes until the buffer is aligned, and then continuing with the old code. However, since GCC is optimizing the rest of the copy to a SSE loop, I question the value of even having the manual Uint32 copy. When I changed the loop to a simple Uint8 copy loop GCC optimized it to a call to memset. Is there a platform without memset available?