mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Fix char overflow in Analogue Mode
In aa7b63fa5f, I didn't notice that the
result was implicitly being converted to int by the min/max from before.
I instead added it to the existing char, but that resulted in a char
overflow (it's unsigned, so thankfully not undefined behavior).
But of course the entire point of that commit is to make it explicitly
clear when you are converting between types, intentionally or otherwise,
in min/max comparisons. So despite causing a regression (which I have
now fixed), at least it did its job.
This commit is contained in:
@@ -336,6 +336,7 @@ SDL_Surface* ApplyFilter( SDL_Surface* _src )
|
|||||||
Uint8 red = (pixelOffset & _src->format->Rmask) >> 16 ;
|
Uint8 red = (pixelOffset & _src->format->Rmask) >> 16 ;
|
||||||
|
|
||||||
double mult;
|
double mult;
|
||||||
|
int tmp; /* needed to avoid char overflow */
|
||||||
if(isscrolling && sampley > 220 && ((rand() %10) < 4))
|
if(isscrolling && sampley > 220 && ((rand() %10) < 4))
|
||||||
{
|
{
|
||||||
mult = 0.6;
|
mult = 0.6;
|
||||||
@@ -345,12 +346,12 @@ SDL_Surface* ApplyFilter( SDL_Surface* _src )
|
|||||||
mult = 0.2;
|
mult = 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
red += fRandom() * mult * 254;
|
tmp = red + fRandom() * mult * 254;
|
||||||
red = SDL_min(red, 255);
|
red = SDL_min(tmp, 255);
|
||||||
green += fRandom() * mult * 254;
|
tmp = green + fRandom() * mult * 254;
|
||||||
green = SDL_min(green, 255);
|
green = SDL_min(tmp, 255);
|
||||||
blue += fRandom() * mult * 254;
|
tmp = blue + fRandom() * mult * 254;
|
||||||
blue = SDL_min(blue, 255);
|
blue = SDL_min(tmp, 255);
|
||||||
|
|
||||||
if(y % 2 == 0)
|
if(y % 2 == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user