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 - SDL_memset4() freeze
Summary: SDL_memset4() freeze
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: Other Other
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-28 15:57 UTC by Jehan
Modified: 2009-08-07 03:20 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 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!