summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2014-10-31 12:13:07 (GMT)
committerSwift Review <review@swift.im>2014-10-31 13:37:24 (GMT)
commitba9f38b5236a649355ea3db43e104ae001a6325e (patch)
tree83a0ff02911a1e974904bbd07ca5c3bfe5bb0c11
parent31cf91f23967a031972bb9d79890f0b2df5cbaa6 (diff)
downloadswift-ba9f38b5236a649355ea3db43e104ae001a6325e.zip
swift-ba9f38b5236a649355ea3db43e104ae001a6325e.tar.bz2
Fix possible NULL pointer dereference in spell checker.
Test-Information: Not manually tested. Change-Id: I1bd6d73388a95f6438606ff44011db849c024225
-rw-r--r--SwifTools/HunspellChecker.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/SwifTools/HunspellChecker.cpp b/SwifTools/HunspellChecker.cpp
index e9bc558..4c3f634 100644
--- a/SwifTools/HunspellChecker.cpp
+++ b/SwifTools/HunspellChecker.cpp
@@ -27,15 +27,17 @@ bool HunspellChecker::isCorrect(const std::string& word) {
void HunspellChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) {
char **suggestList = NULL;
- int words_returned;
+ int words_returned = 0;
if (!word.empty()) {
words_returned = speller_->suggest(&suggestList, word.c_str());
+ if (suggestList != NULL) {
+ for (int i = 0; i < words_returned; ++i) {
+ list.push_back(suggestList[i]);
+ free(suggestList[i]);
+ }
+ free(suggestList);
+ }
}
- for (int i = 0; i < words_returned; ++i) {
- list.push_back(suggestList[i]);
- free(suggestList[i]);
- }
- free(suggestList);
}
void HunspellChecker::checkFragment(const std::string& fragment, PositionPairList& misspelledPositions) {