From ba9f38b5236a649355ea3db43e104ae001a6325e Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Fri, 31 Oct 2014 13:13:07 +0100
Subject: Fix possible NULL pointer dereference in spell checker.

Test-Information:

Not manually tested.

Change-Id: I1bd6d73388a95f6438606ff44011db849c024225

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) {
-- 
cgit v0.10.2-6-g49f6