Prevent ASAN warning:

like SDL_triangle.c:305:30: runtime error: left shift of negative value -672
(even if the value was correctly computed)
main
Sylvain 2024-01-12 15:43:49 +01:00 committed by Sam Lantinga
parent f0b9c7f0f0
commit 4033a0a83b
1 changed files with 33 additions and 15 deletions

View File

@ -112,10 +112,23 @@ static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
return 0; return 0;
} }
/* x = (y << FP_BITS) */
/* prevent runtime error: left shift of negative value */
#define PRECOMP(x, y) \
val = y; \
if (val >= 0) { \
x = val << FP_BITS; \
} else { \
val *= -1; \
x = val << FP_BITS; \
x *= -1; \
}
void trianglepoint_2_fixedpoint(SDL_Point *a) void trianglepoint_2_fixedpoint(SDL_Point *a)
{ {
a->x <<= FP_BITS; int val;
a->y <<= FP_BITS; PRECOMP(a->x, a->x);
PRECOMP(a->y, a->y);
} }
/* bounding rect of three points (in fixed point) */ /* bounding rect of three points (in fixed point) */
@ -297,12 +310,15 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
is_clockwise = area > 0; is_clockwise = area > 0;
area = SDL_abs(area); area = SDL_abs(area);
d2d1_y = (d1->y - d2->y) << FP_BITS; {
d0d2_y = (d2->y - d0->y) << FP_BITS; int val;
d1d0_y = (d0->y - d1->y) << FP_BITS; PRECOMP(d2d1_y, d1->y - d2->y)
d1d2_x = (d2->x - d1->x) << FP_BITS; PRECOMP(d0d2_y, d2->y - d0->y)
d2d0_x = (d0->x - d2->x) << FP_BITS; PRECOMP(d1d0_y, d0->y - d1->y)
d0d1_x = (d1->x - d0->x) << FP_BITS; PRECOMP(d1d2_x, d2->x - d1->x)
PRECOMP(d2d0_x, d0->x - d2->x)
PRECOMP(d0d1_x, d1->x - d0->x)
}
/* Starting point for rendering, at the middle of a pixel */ /* Starting point for rendering, at the middle of a pixel */
{ {
@ -564,13 +580,15 @@ int SDL_SW_BlitTriangle(
is_clockwise = area > 0; is_clockwise = area > 0;
area = SDL_abs(area); area = SDL_abs(area);
d2d1_y = (d1->y - d2->y) << FP_BITS; {
d0d2_y = (d2->y - d0->y) << FP_BITS; int val;
d1d0_y = (d0->y - d1->y) << FP_BITS; PRECOMP(d2d1_y, d1->y - d2->y)
PRECOMP(d0d2_y, d2->y - d0->y)
d1d2_x = (d2->x - d1->x) << FP_BITS; PRECOMP(d1d0_y, d0->y - d1->y)
d2d0_x = (d0->x - d2->x) << FP_BITS; PRECOMP(d1d2_x, d2->x - d1->x)
d0d1_x = (d1->x - d0->x) << FP_BITS; PRECOMP(d2d0_x, d0->x - d2->x)
PRECOMP(d0d1_x, d1->x - d0->x)
}
s2s0_x = s0->x - s2->x; s2s0_x = s0->x - s2->x;
s2s1_x = s1->x - s2->x; s2s1_x = s1->x - s2->x;