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 746

Summary: SDL_memset4() freeze
Product: SDL Reporter: Jehan <jehan.dev>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.0   
Hardware: Other   
OS: Other   

Description Jehan 2009-05-28 15:57:32 UTC
When below SDL_memset4() is called with len = 0. SW is freezing on Iphone platform.

#define SDL_memset4(dst, val, len)		\
do {						\
	unsigned _count = (len);		\
	unsigned _n = (_count + 3) / 4;		\
	Uint32 *_p = SDL_static_cast(Uint32 *, dst);		\
	Uint32 _val = (val);			\
        switch (_count % 4) {			\
        case 0: do {    *_p++ = _val;		\
        case 3:         *_p++ = _val;		\
        case 2:         *_p++ = _val;		\
        case 1:         *_p++ = _val;		\
		} while ( --_n );		\
	}					\
} while(0)

Indeed if we enter the loop when n=0. We will be locked into an infinite loop due to pre-increment (--n).

I assume that this function should just return if len == 0, Do you agree?

I suggest a break when entering the do{}whiile(0) : if(!len) break;
Comment 1 Ozkan Sezer 2009-06-25 10:58:05 UTC
Is SDL-1.2 not affected?
Comment 2 Sam Lantinga 2009-08-07 03:20:56 UTC
Yep, this affected SDL 1.2 as well.  This is now fixed for both versions.

Thanks!