Skip to content

Commit 3b22f35

Browse files
committed
Plugins (oinksie): Fix out-of-bounds access in _oink_gfx_background_floaters
(cherry picked from commit c07e6ed)
1 parent f94b89c commit 3b22f35

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

libvisual-plugins/plugins/actor/oinksie/gfx-background.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ void _oink_gfx_background_circles_filled (OinksiePrivate *priv,
102102
}
103103
}
104104

105+
// In C, `-8 % 5` yields -3 (and `-8 % 5u` yields +3) rather than 2. This wrapper corrects for it.
106+
static int mod(int a, int n) {
107+
const int original = a % n;
108+
return (original >= 0) ? original : (original + n);
109+
}
110+
105111
void _oink_gfx_background_floaters (OinksiePrivate *priv,
106112
uint8_t *buf, int color, int size, int number, int xturn, int yturn, int x, int badd1, int badd2)
107113
{
@@ -117,8 +123,8 @@ void _oink_gfx_background_floaters (OinksiePrivate *priv,
117123

118124
for (i = 0; i < number; i++)
119125
{
120-
xi = (_oink_table_sin[(+xturn + add1) % OINK_TABLE_NORMAL_SIZE] * (float) (priv->screen_width / (number + 1)));
121-
yi = (_oink_table_cos[(+yturn + add2) % OINK_TABLE_NORMAL_SIZE] * (float) (priv->screen_height / 5));
126+
xi = (_oink_table_sin[mod(xturn + add1, OINK_TABLE_NORMAL_SIZE)] * (float) (priv->screen_width / (number + 1)));
127+
yi = (_oink_table_cos[mod(yturn + add2, OINK_TABLE_NORMAL_SIZE)] * (float) (priv->screen_height / 5));
122128

123129
xb = xi + (i * mul) + 20;
124130
yb = yi + x;

0 commit comments

Comments
 (0)