aboutsummaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-11-26 19:32:41 +0100
committerGitHub <noreply@github.com>2021-11-26 19:32:41 +0100
commit87ab97da2ace31fdb46a88a0901ec664dd666feb (patch)
tree71990e03cc72a8780e76a16e9c33cf348c7f05d0 /src/unittest
parentb9051386ae296a6112383725bc8bfcd96dc9a226 (diff)
downloadminetest-87ab97da2ace31fdb46a88a0901ec664dd666feb.tar.gz
minetest-87ab97da2ace31fdb46a88a0901ec664dd666feb.tar.bz2
minetest-87ab97da2ace31fdb46a88a0901ec664dd666feb.zip
Fix find_nodes_in_area misbehaving with out-of-map coordinates (#11770)
This ensures that no overflows (side-effects) happen within the find_nodes_in_area function by limiting coordinates like done in the map generation code.
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/test_voxelarea.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp
index 6ec0412d5..9826d2ee7 100644
--- a/src/unittest/test_voxelarea.cpp
+++ b/src/unittest/test_voxelarea.cpp
@@ -30,6 +30,7 @@ public:
void test_addarea();
void test_pad();
+ void test_extent();
void test_volume();
void test_contains_voxelarea();
void test_contains_point();
@@ -65,6 +66,7 @@ void TestVoxelArea::runTests(IGameDef *gamedef)
{
TEST(test_addarea);
TEST(test_pad);
+ TEST(test_extent);
TEST(test_volume);
TEST(test_contains_voxelarea);
TEST(test_contains_point);
@@ -113,10 +115,22 @@ void TestVoxelArea::test_pad()
UASSERT(v1.MaxEdge == v3s16(-47, -9347, 969));
}
+void TestVoxelArea::test_extent()
+{
+ VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669));
+ UASSERT(v1.getExtent() == v3s16(1191, 995, 1459));
+
+ VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768));
+ UASSERT(v2.getExtent() == v3s16(16, 16, 16));
+}
+
void TestVoxelArea::test_volume()
{
- VoxelArea v1(v3s16(-1337, 447, -789), v3s16(-147, -9547, 669));
- UASSERTEQ(s32, v1.getVolume(), -184657133);
+ VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669));
+ UASSERTEQ(s32, v1.getVolume(), 1728980655);
+
+ VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768));
+ UASSERTEQ(s32, v2.getVolume(), 4096);
}
void TestVoxelArea::test_contains_voxelarea()