diff options
Diffstat (limited to 'gui/predictivedialog.cpp')
-rw-r--r-- | gui/predictivedialog.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/gui/predictivedialog.cpp b/gui/predictivedialog.cpp index 5ce093e054..5d45a3060e 100644 --- a/gui/predictivedialog.cpp +++ b/gui/predictivedialog.cpp @@ -69,7 +69,7 @@ enum { PredictiveDialog::PredictiveDialog() : Dialog("Predictive") { new StaticTextWidget(this, "Predictive.Headline", "Enter Text"); - _btns = (ButtonWidget **)calloc(1, sizeof(ButtonWidget *) * 16); + _btns = (ButtonWidget **)calloc(16, sizeof(ButtonWidget *)); _btns[kCancelAct] = new ButtonWidget(this, "Predictive.Cancel", _("Cancel") , 0, kCancelCmd); _btns[kOkAct] = new ButtonWidget(this, "Predictive.OK", _("Ok") , 0, kOkCmd); @@ -144,6 +144,7 @@ PredictiveDialog::PredictiveDialog() : Dialog("Predictive") { _currentWord.clear(); _wordNumber = 0; _numMatchingWords = 0; + memset(_predictiveResult, 0, sizeof(_predictiveResult)); _lastbutton = kNoAct; _mode = kModePre; @@ -420,6 +421,9 @@ void PredictiveDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 d case kCancelCmd: saveUserDictToFile(); close(); + // When we cancel the dialog no result should be returned. Thus, we + // will invalidate any result here. + _predictiveResult[0] = 0; return; case kOkCmd: _currBtn = kOkAct; @@ -614,7 +618,7 @@ void PredictiveDialog::handleTickle() { void PredictiveDialog::mergeDicts() { _unitedDict.dictLineCount = _predictiveDict.dictLineCount + _userDict.dictLineCount; - _unitedDict.dictLine = (char **)calloc(1, sizeof(char *) * _unitedDict.dictLineCount); + _unitedDict.dictLine = (char **)calloc(_unitedDict.dictLineCount, sizeof(char *)); if (!_unitedDict.dictLine) { debug("Predictive Dialog: cannot allocate memory for united dic"); @@ -748,7 +752,8 @@ bool PredictiveDialog::matchWord() { char tmp[kMaxLineLen]; strncpy(tmp, _unitedDict.dictLine[line], kMaxLineLen); tmp[kMaxLineLen - 1] = 0; - char *tok = strtok(tmp, " "); + char *tok; + strtok(tmp, " "); tok = strtok(NULL, " "); _currentWord = Common::String(tok, _currentCode.size()); return true; @@ -853,7 +858,7 @@ void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Com } // start from here are INSERTING new line to dictionaty ( dict ) - char **newDictLine = (char **)calloc(1, sizeof(char *) * (dict.dictLineCount + 1)); + char **newDictLine = (char **)calloc(dict.dictLineCount + 1, sizeof(char *)); if (!newDictLine) { warning("Predictive Dialog: cannot allocate memory for index buffer"); @@ -861,7 +866,6 @@ void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Com return; } - newDictLine[dict.dictLineCount] = '\0'; int k = 0; bool inserted = false; @@ -883,7 +887,7 @@ void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Com free(dict.dictLine); dict.dictLineCount += 1; - dict.dictLine = (char **)calloc(1, sizeof(char *) * dict.dictLineCount); + dict.dictLine = (char **)calloc(dict.dictLineCount, sizeof(char *)); if (!dict.dictLine) { warning("Predictive Dialog: cannot allocate memory for index buffer"); free(newDictLine); @@ -935,7 +939,7 @@ void PredictiveDialog::loadDictionary(Common::SeekableReadStream *in, Dict &dict ptr++; } - dict.dictLine = (char **)calloc(1, sizeof(char *) * lines); + dict.dictLine = (char **)calloc(lines, sizeof(char *)); if (dict.dictLine == NULL) { warning("Predictive Dialog: Cannot allocate memory for line index buffer"); return; |