diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 00:23:05 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 00:23:05 +0000 |
commit | a784b84a86ec0103b9af04772b573a91684a8a73 (patch) | |
tree | 9f95dbcfccce0c24e2ff9a029962dd71b646cc46 /chrome/renderer | |
parent | b3b2d6e76a2cfbb02933298c565d3718b0288774 (diff) | |
download | chromium_src-a784b84a86ec0103b9af04772b573a91684a8a73.zip chromium_src-a784b84a86ec0103b9af04772b573a91684a8a73.tar.gz chromium_src-a784b84a86ec0103b9af04772b573a91684a8a73.tar.bz2 |
Win: Fix an invalid handle initialization in the spellchecker.
Also, convert a potential crash to a NOTREACHED.
BUG=30433
TEST=see bug
Review URL: http://codereview.chromium.org/505022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck.cc | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc index 3fa20f8..7bc2322 100644 --- a/chrome/renderer/spellchecker/spellcheck.cc +++ b/chrome/renderer/spellchecker/spellcheck.cc @@ -182,6 +182,8 @@ void SpellCheck::InitializeHunspell() { DHISTOGRAM_TIMES("Spellcheck.InitTime", TimeTicks::Now() - start_time); + } else { + NOTREACHED() << "Could not mmap spellchecker dictionary."; } } @@ -201,11 +203,9 @@ bool SpellCheck::InitializeIfNeeded() { return true; } - // Check if the platform spellchecker is being used. - if (file_ != base::kInvalidPlatformFileValue) { - // If it isn't, init hunspell. + // Don't initialize if hunspell is disabled. + if (file_ != base::kInvalidPlatformFileValue) InitializeHunspell(); - } return false; } @@ -223,9 +223,15 @@ bool SpellCheck::CheckSpelling(const string16& word_to_check, int tag) { std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); // Hunspell shouldn't let us exceed its max, but check just in case if (word_to_check_utf8.length() < MAXWORDUTF8LEN) { - // |hunspell_->spell| returns 0 if the word is spelled correctly and - // non-zero otherwsie. - word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); + if (hunspell_.get()) { + // |hunspell_->spell| returns 0 if the word is spelled correctly and + // non-zero otherwsie. + word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); + } else { + // If |hunspell_| is NULL here, an error has occurred, but it's better + // to check rather than crash. + word_correct = true; + } } } @@ -241,6 +247,12 @@ void SpellCheck::FillSuggestionList( wrong_word, optional_suggestions)); return; } + + // If |hunspell_| is NULL here, an error has occurred, but it's better + // to check rather than crash. + if (!hunspell_.get()) + return; + char** suggestions; int number_of_suggestions = hunspell_->suggest(&suggestions, UTF16ToUTF8(wrong_word).c_str()); |