diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-02-02 19:22:45 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-02-02 19:22:45 +0300 |
commit | fc28eefaed2c71a824677b613f87dc4ceaea243b (patch) | |
tree | af0905e94205ac3e18cf130041980c8f675b658f /src/resources/map | |
parent | 59559081b9477a14a748ca66a5ede1b7457c1a46 (diff) | |
download | plus-fc28eefaed2c71a824677b613f87dc4ceaea243b.tar.gz plus-fc28eefaed2c71a824677b613f87dc4ceaea243b.tar.bz2 plus-fc28eefaed2c71a824677b613f87dc4ceaea243b.tar.xz plus-fc28eefaed2c71a824677b613f87dc4ceaea243b.zip |
Fix nullpointer access in special layer draw function.
Diffstat (limited to 'src/resources/map')
-rw-r--r-- | src/resources/map/maplayer.cpp | 4 | ||||
-rw-r--r-- | src/resources/map/maplayer_unittest.cc | 6 | ||||
-rw-r--r-- | src/resources/map/speciallayer_unittest.cc | 45 |
3 files changed, 51 insertions, 4 deletions
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index 95e835302..deaeab9de 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -391,7 +391,7 @@ void MapLayer::drawSpecialLayer(Graphics *const graphics, const MapItem *item0 = mSpecialLayer->mTiles[ptr + startX]; if (!item0 || item0->mType == MapItemType::EMPTY) { - x0 += mSpecialLayer->mCache[ptr + startX]; + x0 += mSpecialLayer->mCache[ptr + startX] + 1; } for (int x = x0; x < endX1; x++) { @@ -414,7 +414,7 @@ void MapLayer::drawSpecialLayer(Graphics *const graphics, item0 = mTempLayer->mTiles[ptr + startX]; if (!item0 || item0->mType == MapItemType::EMPTY) { - x0 += mTempLayer->mCache[ptr + startX]; + x0 += mTempLayer->mCache[ptr + startX] + 1; } for (int x = x0; x < endX1; x++) { diff --git a/src/resources/map/maplayer_unittest.cc b/src/resources/map/maplayer_unittest.cc index 103d019cd..bd58d998c 100644 --- a/src/resources/map/maplayer_unittest.cc +++ b/src/resources/map/maplayer_unittest.cc @@ -2117,8 +2117,14 @@ TEST_CASE("MapLayer drawSpecialLayer (tempLayer)") layer->setTempLayer(map->getTempLayer()); TileInfo *const tiles = layer->getTiles(); specialLayer = map->getTempLayer(); + const int *const cache = specialLayer->getCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + specialLayer->setTile(1, 0, MapItemType::ARROW_UP); specialLayer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 10000); layer->drawSpecialLayer(mock, 0, diff --git a/src/resources/map/speciallayer_unittest.cc b/src/resources/map/speciallayer_unittest.cc index 3e1b42043..b74ade7dc 100644 --- a/src/resources/map/speciallayer_unittest.cc +++ b/src/resources/map/speciallayer_unittest.cc @@ -62,8 +62,9 @@ TEST_CASE("SpecialLayer updateCache") { layer = new SpecialLayer("test", 1, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); const int *const cache = layer->getCache(); + REQUIRE(cache[0] == 10000); + layer->setTile(0, 0, MapItemType::ARROW_UP); layer->updateCache(); REQUIRE(cache[0] == 10000); } @@ -72,8 +73,10 @@ TEST_CASE("SpecialLayer updateCache") { layer = new SpecialLayer("test", 2, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); const int *const cache = layer->getCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + layer->setTile(0, 0, MapItemType::ARROW_UP); layer->updateCache(); REQUIRE(cache[0] == 10000); REQUIRE(cache[1] == 10000); @@ -143,6 +146,44 @@ TEST_CASE("SpecialLayer updateCache") REQUIRE(cache[2] == 10000); } + SECTION("simple 7") + { + layer = new SpecialLayer("test", + 3, 1); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 8") + { + layer = new SpecialLayer("test", + 3, 1); + layer->setTile(0, 0, MapItemType::EMPTY); + layer->setTile(1, 0, MapItemType::EMPTY); + layer->setTile(2, 0, MapItemType::EMPTY); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 9") + { + layer = new SpecialLayer("test", + 2, 1); + const int *const cache = layer->getCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + layer->setTile(1, 0, MapItemType::ARROW_UP); + layer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 10000); + } + SECTION("normal 1") { layer = new SpecialLayer("test", |