| Summary: | fallback code for SDL_memset alignment error | ||
|---|---|---|---|
| Product: | SDL | Reporter: | skaller <skaller> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED DUPLICATE | QA Contact: | Sam Lantinga <slouken> |
| Severity: | minor | ||
| Priority: | P2 | CC: | yuriks |
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | All | ||
SDL_string.c line 266 to 288 contains this replacement code for ISO C memset: dstp4 = (Uint32 *) dst; len /= 4; while (len--) { *dstp4++ = value4; } This code may not work correctly if argument dst is not aligned on a 4 byte boundary. In addition this calculation is incorrect: Uint32 value4 = (c | (c << 8) | (c << 16) | (c << 24)); at least because 255^24 is certain to cause overflow. In addition bitwise or operator applied to signed values is not well defined. This can be fixed by casting the argument to type Uint8 or at least Uint32. However none of this matters because the whole replacement code is unnecessary. memset is available in all C implementations. If a fallback is really necessary attempting to optimise behaviour seems pointless and a simple for loop will suffice.