[Mesa-dev] [PATCH 06/10] mesa: Prevent negative indexing on noise2, noise3 and noise4
Juha-Pekka Heikkila
juhapekka.heikkila at gmail.com
Mon Feb 17 08:21:29 PST 2014
% operator could return negative value which would cause
indexing before perm table.
Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
src/mesa/program/prog_noise.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/mesa/program/prog_noise.c b/src/mesa/program/prog_noise.c
index c258c5e..12bb4d9 100644
--- a/src/mesa/program/prog_noise.c
+++ b/src/mesa/program/prog_noise.c
@@ -282,8 +282,8 @@ _mesa_noise2(GLfloat x, GLfloat y)
y2 = y0 - 1.0f + 2.0f * G2;
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
- ii = i % 256;
- jj = j % 256;
+ ii = abs(i % 256);
+ jj = abs(j % 256);
/* Calculate the contribution from the three corners */
t0 = 0.5f - x0 * x0 - y0 * y0;
@@ -423,9 +423,9 @@ _mesa_noise3(GLfloat x, GLfloat y, GLfloat z)
z3 = z0 - 1.0f + 3.0f * G3;
/* Wrap the integer indices at 256 to avoid indexing perm[] out of bounds */
- ii = i % 256;
- jj = j % 256;
- kk = k % 256;
+ ii = abs(i % 256);
+ jj = abs(j % 256);
+ kk = abs(k % 256);
/* Calculate the contribution from the four corners */
t0 = 0.6f - x0 * x0 - y0 * y0 - z0 * z0;
@@ -573,10 +573,10 @@ _mesa_noise4(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
w4 = w0 - 1.0f + 4.0f * G4;
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
- ii = i % 256;
- jj = j % 256;
- kk = k % 256;
- ll = l % 256;
+ ii = abs(i % 256);
+ jj = abs(j % 256);
+ kk = abs(k % 256);
+ ll = abs(l % 256);
/* Calculate the contribution from the five corners */
t0 = 0.6f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
--
1.8.1.2
More information about the mesa-dev
mailing list