fixed illegal access in bump.c
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 2 Oct 2016 19:08:34 +0000 (22:08 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 2 Oct 2016 19:08:34 +0000 (22:08 +0300)
src/bump.c

index 228e141..dc53337 100644 (file)
@@ -91,8 +91,8 @@ static int init(void)
                        const float offsetPower = 2.0f;
                        int dx, dy, xp, yp;
 
                        const float offsetPower = 2.0f;
                        int dx, dy, xp, yp;
 
-                       dx = (int)((heightmap[i] - heightmap[i + 1]) * offsetPower);
-                       dy = (int)((heightmap[i] - heightmap[i + fb_width]) * offsetPower);
+                       dx = i < fb_size - 1 ? (int)((heightmap[i] - heightmap[i + 1]) * offsetPower) : 0;
+                       dy = i < fb_size - fb_width ? (int)((heightmap[i] - heightmap[i + fb_width]) * offsetPower) : 0;
 
                        xp = x + dx;
                        if (xp < 0) xp = 0;
 
                        xp = x + dx;
                        if (xp < 0) xp = 0;