From ae28fb2988badf1bceb7cbf85a89e6143d3d4536 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 9 Mar 2011 23:26:03 +0100 Subject: Prevented a potential crash in storage::getAllWorldStateVars() Minor other fixes. Trivial. --- src/account-server/storage.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 2326dec6..50b131b7 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -1509,6 +1509,14 @@ std::map Storage::getAllWorldStateVars(int mapId) { std::map variables; + // Avoid a crash because prepared statements must have at least one binding. + if (mapId < 0) + { + LOG_ERROR("getAllWorldStateVars was called with a negative map Id: " + << mapId); + return variables; + } + try { std::ostringstream query; @@ -1527,7 +1535,7 @@ std::map Storage::getAllWorldStateVars(int mapId) mDb->bindValue(1, mapId); const dal::RecordSet &results = mDb->processSql(); - for (unsigned int i = 0; i < results.rows(); i++) + for (unsigned int i = 0; i < results.rows(); ++i) { variables[results(i, 0)] = results(i, 1); } @@ -1588,7 +1596,7 @@ void Storage::setWorldStateVar(const std::string &name, mDb->execSql(updateStateVar.str()); // If we updated a row, were finished here - if (mDb->getModifiedRows() >= 1) + if (mDb->getModifiedRows() > 0) return; // Otherwise we have to add the new variable -- cgit v1.2.3-60-g2f50