diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index c9b8127f68..58ad094519 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include "../../model/doc/document.hpp" #include "../../model/world/universalid.hpp" #include "../../model/world/data.hpp" @@ -210,18 +212,28 @@ void CSVWorld::ScriptSubView::useHint (const std::string& hint) unsigned line = 0, column = 0; char c; std::istringstream stream (hint.c_str()+1); - switch(hint[0]){ + switch(hint[0]) + { case 'R': case 'r': { QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn); QString source = mModel->data (index).toString(); + unsigned stringSize = source.length(); unsigned pos, dummy; if (!(stream >> c >> dummy >> pos) ) return; - for (unsigned i = 0; i <= pos; ++i){ - if (source[i] == '\n'){ + if (pos > stringSize) + { + Log(Debug::Warning) << "CSVWorld::ScriptSubView: requested position is higher than actual string length"; + pos = stringSize; + } + + for (unsigned i = 0; i <= pos; ++i) + { + if (source[i] == '\n') + { ++line; column = i+1; } @@ -231,7 +243,7 @@ void CSVWorld::ScriptSubView::useHint (const std::string& hint) } case 'l': if (!(stream >> c >> line >> column)) - return; + return; } QTextCursor cursor = mEditor->textCursor(); diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index 29dbe03913..b20805a117 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -338,6 +338,9 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) if (!comments.empty() && index != -1 && settingRegex.captureCount() >= 2 && mUserSettings.find(settingRegex.cap(1)) != mUserSettings.end()) { + if (commentStart == fileCopy.end()) + throw std::runtime_error("Config::GameSettings: failed to parse settings - iterator is past of end of settings file"); + for (std::vector::const_iterator it = comments.begin(); it != comments.end(); ++it) { *commentStart = *it;