From 4109968fed02cfd6ca7e3bbf7f256a021448b2a8 Mon Sep 17 00:00:00 2001 From: Gres Date: Wed, 17 Oct 2018 19:32:55 +0300 Subject: [PATCH] Fixed possible wrong index usage --- TranslatorHelper.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/TranslatorHelper.cpp b/TranslatorHelper.cpp index 68e48e8..fcae228 100644 --- a/TranslatorHelper.cpp +++ b/TranslatorHelper.cpp @@ -61,6 +61,9 @@ void TranslatorHelper::loadScripts () { void TranslatorHelper::newItem (bool forceRotate) { triesLeft_ = scripts_.size (); currentIndex_ = forceRotate ? currentIndex_ + 1 : 0; + if (currentIndex_ >= scripts_.size ()) { + currentIndex_ = 0; + } } QString TranslatorHelper::nextScript () { @@ -74,7 +77,10 @@ QString TranslatorHelper::nextScript () { } QString TranslatorHelper::currentScript () const { - return (triesLeft_ > 0 ? scripts_.at (currentIndex_) : QString ()); + if (triesLeft_ > 0 && currentIndex_ < scripts_.size ()) { + return scripts_.at (currentIndex_); + } + return QString (); } bool TranslatorHelper::gotScripts () const {