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 4283 - SDL's version of memset is different from libc's
Summary: SDL's version of memset is different from libc's
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.9
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-28 20:59 UTC by janisozaur
Modified: 2018-10-01 17:11 UTC (History)
2 users (show)

See Also:


Attachments
reproducer.c (1.40 KB, patch)
2018-09-28 20:59 UTC, janisozaur
Details | Diff
0001-SDL_memset-correct-the-passed-argument.patch (916 bytes, patch)
2018-09-28 21:01 UTC, janisozaur
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description janisozaur 2018-09-28 20:59:19 UTC
Created attachment 3328 [details]
reproducer.c

memset's documentation reads:

* The memset() function shall copy c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s. (http://pubs.opengroup.org/onlinepubs/9699919799/functions/memset.html)
* Sets the first count characters of dest to the character c. (https://msdn.microsoft.com/en-us/library/1fdeehz6.aspx)
* write a byte to a byte string (https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/memset.3.html)

The highlight here is they all mean a single _byte_, even though memset receives a parameter of type int, which can hold more data than a single byte. SDL's implementation of memset, however, does not clear any of the higher bits, causing an erroneous behaviour when passed an argument bigger than 0xff.

Please find attached reproducer and proposed patch.
Comment 1 janisozaur 2018-09-28 21:01:34 UTC
Created attachment 3329 [details]
0001-SDL_memset-correct-the-passed-argument.patch
Comment 2 Sam Lantinga 2018-09-29 03:48:37 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/9f3949b8ec40
Comment 3 Ozkan Sezer 2018-09-30 18:39:21 UTC
As far as I can see, video/SDL_fillrect.c::SDL_FillRect1SSE() for e.g.
will probably have different output after this change, might (or might
not) need adjusting.
Comment 4 Sam Lantinga 2018-10-01 16:26:49 UTC
Nope, that already takes an 8 bit color value so it should be good.

Thanks for checking!
Comment 5 Ozkan Sezer 2018-10-01 17:11:52 UTC
My mistake.  Thanks for clarifying.