1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-30 17:36:40 +00:00

Avoid possible division by zero

components/detournavigator/navmeshdb.cpp:183:43: warning: Division by zero [clang-analyzer-core.DivideZero]
        setMaxPageCount(*mDb, maxFileSize / dbPageSize + static_cast<std::uint64_t>((maxFileSize % dbPageSize) != 0));
                              ~~~~~~~~~~~~^~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:182:33: note: Calling 'getPageSize'
        const auto dbPageSize = getPageSize(*mDb);
                                ^~~~~~~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:144:13: note: 'value' initialized to 0
            std::uint64_t value = 0;
            ^~~~~~~~~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:145:13: note: Calling 'request<DetourNavigator::(anonymous namespace)::GetPageSize, unsigned long *, >'
            request(db, statement, &value, 1);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
components/sqlite3/request.hpp:254:64: note: Left side of '&&' is false
            for (std::size_t i = 0; executeStep(db, statement) && i < max; ++i)
                                                               ^
components/detournavigator/navmeshdb.cpp:145:13: note: Returning from 'request<DetourNavigator::(anonymous namespace)::GetPageSize, unsigned long *, >'
            request(db, statement, &value, 1);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:146:13: note: Returning zero (loaded from 'value')
            return value;
            ^~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:182:33: note: Returning from 'getPageSize'
        const auto dbPageSize = getPageSize(*mDb);
                                ^~~~~~~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:182:9: note: 'dbPageSize' initialized to 0
        const auto dbPageSize = getPageSize(*mDb);
        ^~~~~~~~~~~~~~~~~~~~~
components/detournavigator/navmeshdb.cpp:183:43: note: Division by zero
        setMaxPageCount(*mDb, maxFileSize / dbPageSize + static_cast<std::uint64_t>((maxFileSize % dbPageSize) != 0));
                              ~~~~~~~~~~~~^~~~~~~~~~~~
This commit is contained in:
elsid 2022-07-06 12:49:02 +02:00
parent f1ded70366
commit 5b9ca3b979
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625

View file

@ -179,7 +179,9 @@ namespace DetourNavigator
, mInsertShape(*mDb, DbQueries::InsertShape {})
, mVacuum(*mDb, DbQueries::Vacuum {})
{
const auto dbPageSize = getPageSize(*mDb);
const std::uint64_t dbPageSize = getPageSize(*mDb);
if (dbPageSize == 0)
throw std::runtime_error("NavMeshDb page size is zero");
setMaxPageCount(*mDb, maxFileSize / dbPageSize + static_cast<std::uint64_t>((maxFileSize % dbPageSize) != 0));
}