Skip to content

Commit

Permalink
Cavegen: Fix possible out-of-bounds heightmap access
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Dec 1, 2013
1 parent 20e3d55 commit f3439c4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cavegen.cpp
Expand Up @@ -518,7 +518,8 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;

if (!is_ravine && mg->heightmap && should_make_cave_hole) {
if (!is_ravine && mg->heightmap && should_make_cave_hole &&
p.X <= node_max.X && p.Z <= node_max.Z) {
int maplen = node_max.X - node_min.X + 1;
int idx = (p.Z - node_min.Z) * maplen + (p.X - node_min.X);
if (p.Y >= mg->heightmap[idx] - 2)
Expand Down

0 comments on commit f3439c4

Please sign in to comment.