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 2030

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   

Description skaller 2013-08-11 09:20:57 UTC
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.
Comment 1 Yuri K. Schlesner 2014-05-19 04:26:45 UTC
I believe I duped this in bug 2536.

*** This bug has been marked as a duplicate of bug 2536 ***