[patch/rfc] fix segfault in SDL_CalculateBlitN() introduced by altivec code

with libsdl-1.2.9, some games (like bomberclone) started segfaulting in
Gentoo … with the help of Aaron in the Gentoo bugzilla, we traced it back
to this change:
http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/SDL_blit_N.c.diff?r1=1.9&r2=1.10

the last change in the last hunk:
-(table[which].cpu_mmx == SDL_HasMMX())
+(table[which].blit_features & GetBlitFeatures()) ==
table[which].blit_features)

the bug seems to be that on non-altivec systems, if blit_features is 0, this
statement returns true when it used to return false

(table[which].cpu_mmx == SDL_HasMMX()))
0 == 1
(table[which].blit_features & GetBlitFeatures()) ==
table[which].blit_features)
(0 & 1) == 0

if i change the statement to read:
(table[which].blit_features & GetBlitFeatures()) == GetBlitFeatures()

bomberclone no longer segfaults on my box

can anyone else confirm this ?

Gentoo bug report:
http://bugs.gentoo.org/104533
-mike
-------------- next part --------------
A non-text attachment was scrubbed…
Name: libsdl-1.2.9-sdl-blit-mmx-check.patch
Type: text/x-diff
Size: 551 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20051229/1d5ffbc6/attachment.patch

Of Mike Frysinger wrote:

with libsdl-1.2.9, some games (like bomberclone) started segfaulting in
Gentoo

the last change in the last hunk:
-(table[which].cpu_mmx == SDL_HasMMX())
+(table[which].blit_features & GetBlitFeatures()) ==
table[which].blit_features)

the bug seems to be that on non-altivec systems, if blit_features is 0,
this statement returns true when it used to return false

if i change the statement to read:
(table[which].blit_features & GetBlitFeatures()) == GetBlitFeatures()
bomberclone no longer segfaults on my box

The test “(table[which].blit_features & GetBlitFeatures()) ==
table[which].blit_features)” is correct, and the previous
"(table[which].cpu_mmx == SDL_HasMMX())" was actually broken.
The test you are suggesting would invariably select the slowest possible
blitter (BlitNtoN) on systems that have many cpu features present. The
previous test was also selecting the slow unoptimized blitter on systems
that did have MMX, skipping the optimized C versions.

You should find out which function actually segfaults and back-track from
there (compile bomberclone with debug info and no SDL_PARACHUTE).

-Alex.