fix undefined behaviour in various places
these were found by UBSan in clang builds. they don't show up in gcc builds
This commit is contained in:
parent
d2ed6b8571
commit
837c02c791
7 changed files with 36 additions and 9 deletions
|
@ -195,6 +195,10 @@ void draw_boss(Boss *boss) {
|
|||
hpspan += boss->attacks[prevspell].hp;
|
||||
}
|
||||
|
||||
if(!maxhpspan) {
|
||||
return;
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(10,2,0);
|
||||
glScalef((VIEWPORT_W-60)/(float)maxhpspan,1,1);
|
||||
|
|
23
src/color.c
23
src/color.c
|
@ -12,16 +12,25 @@
|
|||
static const float conv = 1.0f / CLR_ONEVALUE;
|
||||
|
||||
Color rgba(float r, float g, float b, float a) {
|
||||
return ((((Color)(CLR_ONEVALUE * (r)) & CLR_CMASK) << CLR_R) + \
|
||||
(((Color)(CLR_ONEVALUE * (g)) & CLR_CMASK) << CLR_G) + \
|
||||
(((Color)(CLR_ONEVALUE * (b)) & CLR_CMASK) << CLR_B) + \
|
||||
(((Color)(CLR_ONEVALUE * (a)) & CLR_CMASK) << CLR_A));
|
||||
assert(!r || isnormal(r));
|
||||
assert(!g || isnormal(g));
|
||||
assert(!b || isnormal(b));
|
||||
assert(!a || isnormal(a));
|
||||
|
||||
return ((((Color)(ColorComponent)(CLR_ONEVALUE * (r)) & CLR_CMASK) << CLR_R) + \
|
||||
(((Color)(ColorComponent)(CLR_ONEVALUE * (g)) & CLR_CMASK) << CLR_G) + \
|
||||
(((Color)(ColorComponent)(CLR_ONEVALUE * (b)) & CLR_CMASK) << CLR_B) + \
|
||||
(((Color)(ColorComponent)(CLR_ONEVALUE * (a)) & CLR_CMASK) << CLR_A));
|
||||
}
|
||||
|
||||
Color rgb(float r, float g, float b) {
|
||||
return ((((Color)(CLR_ONEVALUE * (r)) & CLR_CMASK) << CLR_R) + \
|
||||
(((Color)(CLR_ONEVALUE * (g)) & CLR_CMASK) << CLR_G) + \
|
||||
(((Color)(CLR_ONEVALUE * (b)) & CLR_CMASK) << CLR_B) + \
|
||||
assert(!r || isnormal(r));
|
||||
assert(!g || isnormal(g));
|
||||
assert(!b || isnormal(b));
|
||||
|
||||
return ((((Color)(ColorComponent)(CLR_ONEVALUE * (r)) & CLR_CMASK) << CLR_R) + \
|
||||
(((Color)(ColorComponent)(CLR_ONEVALUE * (g)) & CLR_CMASK) << CLR_G) + \
|
||||
(((Color)(ColorComponent)(CLR_ONEVALUE * (b)) & CLR_CMASK) << CLR_B) + \
|
||||
(CLR_ONEVALUE << CLR_A));
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,10 @@ int collision_line(complex a, complex b, complex c, float r) {
|
|||
la = a*conj(a);
|
||||
lm = m*conj(m);
|
||||
|
||||
if(!lm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
d = -(creal(a)*creal(m)+cimag(a)*cimag(m))/lm;
|
||||
|
||||
s = d*d - (la - r*r)/lm;
|
||||
|
|
|
@ -173,9 +173,15 @@ void draw_main_menu(MenuData *menu) {
|
|||
float ry = sin(913*i+137*cycle);
|
||||
float rz = sin(1303*i+89631*cycle);
|
||||
float r = sqrt(rx*rx+ry*ry+rz*rz);
|
||||
|
||||
if(!r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rx /= r;
|
||||
ry /= r;
|
||||
rz /= r;
|
||||
|
||||
if(posx > SCREEN_W+20 || posy < -20 || posy > SCREEN_H+20)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ static void stage_draw_objects(void) {
|
|||
|
||||
if(boss_is_dying(global.boss)) {
|
||||
float t = (global.frames - global.boss->current->endtime)/(float)BOSS_DEATH_DELAY + 1;
|
||||
f -= t*(t-0.7)/(1-t);
|
||||
f -= t*(t-0.7)/max(0.01, 1-t);
|
||||
}
|
||||
|
||||
glScalef(f,f,f);
|
||||
|
|
|
@ -680,6 +680,10 @@ void stage3_boss_a2_warnlaser_logic(Laser *l, int time) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(time < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
l->width = laser_charge(l, time, 90, 10);
|
||||
l->color = mix_colors(rgb(1, 0.2, 0.2), rgb(0.2, 0.2, 1), time / l->deathtime);
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ void limit_frame_rate(uint64_t *lasttime) {
|
|||
}
|
||||
|
||||
double passed = (double)(SDL_GetPerformanceCounter() - *lasttime) / SDL_GetPerformanceFrequency();
|
||||
double delay = 1.0 / FPS - passed;
|
||||
double delay = max(0, 1.0 / FPS - passed);
|
||||
uint32_t delay_ms = (uint32_t)(delay * 1000.0);
|
||||
|
||||
if(delay > 0 && delay_ms > 0) {
|
||||
|
|
Loading…
Reference in a new issue