diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 23:22:43 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 23:22:43 +0000 |
commit | 6181e4bd41ceb43c05076ca83e989cad9bc80643 (patch) | |
tree | d5cb186dbed0ff2e77d6926593faf8a0bc012c58 | |
parent | 7f860dd842e8e4aab9d2b16dc6c804e4fbc6235a (diff) | |
download | chromium_src-6181e4bd41ceb43c05076ca83e989cad9bc80643.zip chromium_src-6181e4bd41ceb43c05076ca83e989cad9bc80643.tar.gz chromium_src-6181e4bd41ceb43c05076ca83e989cad9bc80643.tar.bz2 |
Blind fix for a crash due to r54649. Committing results can mean the provided is no longer valid. In that case the best we can do is to clamp to the valid range.
BUG=51634
TEST=none (hard to reproduce this)
Review URL: http://codereview.chromium.org/3139001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55495 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_model.cc | 14 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_model.h | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 795c03a..3f223b9 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -82,17 +82,19 @@ void AutocompletePopupModel::SetHoveredLine(size_t line) { void AutocompletePopupModel::SetSelectedLine(size_t line, bool reset_to_default) { - // We should at least be dealing with the results of the current query. + // We should at least be dealing with the results of the current query. Note + // that even if |line| was valid on entry, this may make it invalid. We clamp + // it below. controller_->CommitIfQueryHasNeverBeenCommitted(); const AutocompleteResult& result = controller_->result(); - CHECK(line < result.size()); if (result.empty()) return; // Cancel the query so the matches don't change on the user. controller_->Stop(false); + line = std::min(line, result.size() - 1); const AutocompleteMatch& match = result.match_at(line); if (reset_to_default) { manually_selected_match_.Clear(); @@ -236,8 +238,8 @@ void AutocompletePopupModel::Move(int count) { // Clamp the new line to [0, result_.count() - 1]. const size_t new_line = selected_line_ + count; - SetSelectedLine((((count < 0) && (new_line >= selected_line_)) ? - 0 : std::min(new_line, result.size() - 1)), false); + SetSelectedLine(((count < 0) && (new_line >= selected_line_)) ? 0 : new_line, + false); } void AutocompletePopupModel::TryDeletingCurrentItem() { @@ -259,10 +261,12 @@ void AutocompletePopupModel::TryDeletingCurrentItem() { const AutocompleteResult& result = controller_->result(); if (!result.empty()) { // Move the selection to the next choice after the deleted one. + // SetSelectedLine() will clamp to take care of the case where we deleted + // the last item. // TODO(pkasting): Eventually the controller should take care of this // before notifying us, reducing flicker. At that point the check for // deletability can move there too. - SetSelectedLine(std::min(result.size() - 1, selected_line), false); + SetSelectedLine(selected_line, false); } } } diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.h b/chrome/browser/autocomplete/autocomplete_popup_model.h index 818ff2b..488cd9e 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.h +++ b/chrome/browser/autocomplete/autocomplete_popup_model.h @@ -65,7 +65,7 @@ class AutocompletePopupModel : public NotificationObserver { // Call to change the selected line. This will update all state and repaint // the necessary parts of the window, as well as updating the edit with the - // new temporary text. |line| should be within the range of valid lines. + // new temporary text. |line| will be clamped to the range of valid lines. // |reset_to_default| is true when the selection is being reset back to the // default match, and thus there is no temporary text (and no // |manually_selected_match_|). |