diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-24 23:27:05 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-24 23:27:05 +0100 |
commit | 58c94ce5b5ff5074ebb336559f9d35f738476c89 (patch) | |
tree | 84aa0b26720ecdb22d850f41a1189d8f13d80b5c /src | |
parent | 3adb32e27798c59b4477a86484a3c82b75ce574d (diff) |
fix chunk predicate use-after-free
Diffstat (limited to 'src')
-rw-r--r-- | src/chunk-region.cpp | 32 | ||||
-rw-r--r-- | src/chunk.hpp | 1 |
2 files changed, 16 insertions, 17 deletions
diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp index 67c474bc..54696bc0 100644 --- a/src/chunk-region.cpp +++ b/src/chunk-region.cpp @@ -111,26 +111,15 @@ tmp_s& get_tmp() return *tmp; } -} // namespace - -void chunk::delete_pass_region(pass_region*& ptr) -{ - if (ptr) - { - delete ptr; - ptr = nullptr; - } -} - -pred chunk::default_region_predicate() noexcept +auto default_region_predicate(chunk& c) noexcept { - return [this](collision_data data) { + return [&c](collision_data data) { auto x = std::bit_cast<collision_data>(data); // XXX 'scenery' is used for all object types if (x.tag == (uint64_t)collision_type::scenery) { - auto& w = _world; - auto obj = w->find_object(x.data); + auto& w = c.world(); + auto obj = w.find_object(x.data); if (obj->type() == object_type::critter) return path_search_continue::pass; } @@ -138,6 +127,17 @@ pred chunk::default_region_predicate() noexcept }; } +} // namespace + +void chunk::delete_pass_region(pass_region*& ptr) +{ + if (ptr) + { + delete ptr; + ptr = nullptr; + } +} + auto chunk::get_pass_region() -> const pass_region* { if (!_region_modified) @@ -161,7 +161,7 @@ void chunk::mark_region_modified() noexcept { _region_modified = true; } void chunk::make_pass_region(pass_region& ret) { - return make_pass_region(ret, default_region_predicate()); + return make_pass_region(ret, default_region_predicate(*this)); } void chunk::make_pass_region(pass_region& ret, const pred& f) diff --git a/src/chunk.hpp b/src/chunk.hpp index cc48bb26..217bd35a 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -119,7 +119,6 @@ public: static constexpr size_t max_wall_quad_count = TILE_COUNT*Wall::Direction_COUNT*(Wall::Group_COUNT+4); - detail_astar::pred default_region_predicate() noexcept; const pass_region* get_pass_region(); void make_pass_region(pass_region& ret); void make_pass_region(pass_region& ret, const detail_astar::pred& f); |