From d2d8a7a940b47660f7bd51cc065fbf13119c0179 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 9 Jan 2021 21:58:27 +0100 Subject: [PATCH] Fix passing null to memcpy /home/elsid/dev/openmw/components/detournavigator/navmeshtilescache.cpp:36:24: runtime error: null pointer passed as argument 2, which is declared to never be null #0 0x55e37ba4cda5 in makeNavMeshKey /home/elsid/dev/openmw/components/detournavigator/navmeshtilescache.cpp:36 #1 0x55e37ba4cda5 in DetourNavigator::NavMeshTilesCache::set(osg::Vec3f const&, osg::Vec2i const&, DetourNavigator::RecastMesh const&, std::vector > const&, DetourNavigator::NavMeshData&&) /home/elsid/dev/openmw/components/detournavigator/navmeshtilescache.cpp:81 #2 0x55e37fe3c861 in DetourNavigator::updateNavMesh(osg::Vec3f const&, DetourNavigator::RecastMesh const*, osg::Vec2i const&, osg::Vec2i const&, std::vector > const&, DetourNavigator::Settings const&, std::shared_ptr > const&, DetourNavigator::NavMeshTilesCache&) /home/elsid/dev/openmw/components/detournavigator/makenavmesh.cpp:582 #3 0x55e37fb796ce in DetourNavigator::AsyncNavMeshUpdater::processJob(DetourNavigator::AsyncNavMeshUpdater::Job const&) /home/elsid/dev/openmw/components/detournavigator/asyncnavmeshupdater.cpp:178 #4 0x55e37fb9a125 in DetourNavigator::AsyncNavMeshUpdater::process() /home/elsid/dev/openmw/components/detournavigator/asyncnavmeshupdater.cpp:144 #5 0x7f013f585c23 in execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:80 #6 0x7f013f8c63e8 in start_thread (/usr/lib/libpthread.so.0+0x93e8) #7 0x7f013e91d292 in __GI___clone (/usr/lib/libc.so.6+0x100292) --- .../detournavigator/navmeshtilescache.cpp | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/components/detournavigator/navmeshtilescache.cpp b/components/detournavigator/navmeshtilescache.cpp index f554cd4143..cff93ac0e5 100644 --- a/components/detournavigator/navmeshtilescache.cpp +++ b/components/detournavigator/navmeshtilescache.cpp @@ -21,19 +21,32 @@ namespace DetourNavigator std::vector result(indicesSize + verticesSize + areaTypesSize + waterSize + offMeshConnectionsSize); unsigned char* dst = result.data(); - std::memcpy(dst, recastMesh.getIndices().data(), indicesSize); - dst += indicesSize; + if (indicesSize > 0) + { + std::memcpy(dst, recastMesh.getIndices().data(), indicesSize); + dst += indicesSize; + } - std::memcpy(dst, recastMesh.getVertices().data(), verticesSize); - dst += verticesSize; + if (verticesSize > 0) + { + std::memcpy(dst, recastMesh.getVertices().data(), verticesSize); + dst += verticesSize; + } - std::memcpy(dst, recastMesh.getAreaTypes().data(), areaTypesSize); - dst += areaTypesSize; + if (areaTypesSize > 0) + { + std::memcpy(dst, recastMesh.getAreaTypes().data(), areaTypesSize); + dst += areaTypesSize; + } - std::memcpy(dst, recastMesh.getWater().data(), waterSize); - dst += waterSize; + if (waterSize > 0) + { + std::memcpy(dst, recastMesh.getWater().data(), waterSize); + dst += waterSize; + } - std::memcpy(dst, offMeshConnections.data(), offMeshConnectionsSize); + if (offMeshConnectionsSize > 0) + std::memcpy(dst, offMeshConnections.data(), offMeshConnectionsSize); return result; }