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 - fallback code for SDL_memset alignment error
Summary: fallback code for SDL_memset alignment error
Status: RESOLVED DUPLICATE of bug 2536
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-11 09:20 UTC by skaller
Modified: 2014-05-19 04:26 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***