summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoryusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-06 11:06:12 +0000
committeryusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-06 11:06:12 +0000
commitf54009111abbfa0ad1372c22f943cab3f6fc62e0 (patch)
tree3437643e56428c3ee706610134bab8978f43a8bd /chrome
parentcab703753ebb6f328ac695233181cb188f226855 (diff)
downloadchromium_src-f54009111abbfa0ad1372c22f943cab3f6fc62e0.zip
chromium_src-f54009111abbfa0ad1372c22f943cab3f6fc62e0.tar.gz
chromium_src-f54009111abbfa0ad1372c22f943cab3f6fc62e0.tar.bz2
Add some defensive checks.
Added code that detects array out-of-bounds errors. This should help to debug regressions like http://code.google.com/p/chromium-os/issues/detail?id=2878#c11 . BUG=chromium-os:2878 TEST=see the bug 2878. confirmed that with this change, chrome does not crash. Review URL: http://codereview.chromium.org/2018002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/status/language_menu_button.cc25
1 files changed, 20 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc
index 94c4522..1249a4b0 100644
--- a/chrome/browser/chromeos/status/language_menu_button.cc
+++ b/chrome/browser/chromeos/status/language_menu_button.cc
@@ -333,8 +333,7 @@ void LanguageMenuButton::ActivatedAt(int index) {
return;
}
- // Separators are not clickable.
- NOTREACHED();
+ LOG(ERROR) << "Unexpected index: " << index;
}
////////////////////////////////////////////////////////////////////////////////
@@ -429,9 +428,14 @@ void LanguageMenuButton::RebuildModel() {
bool LanguageMenuButton::IndexIsInInputMethodList(int index) const {
DCHECK_GE(index, 0);
DCHECK(model_.get());
+ if (index >= model_->GetItemCount()) {
+ return false;
+ }
return ((model_->GetTypeAt(index) == menus::MenuModel::TYPE_RADIO) &&
- (model_->GetCommandIdAt(index) == COMMAND_ID_INPUT_METHODS));
+ (model_->GetCommandIdAt(index) == COMMAND_ID_INPUT_METHODS) &&
+ input_method_descriptors_.get() &&
+ (index < static_cast<int>(input_method_descriptors_->size())));
}
bool LanguageMenuButton::GetPropertyIndex(
@@ -439,11 +443,19 @@ bool LanguageMenuButton::GetPropertyIndex(
DCHECK_GE(index, 0);
DCHECK(property_index);
DCHECK(model_.get());
+ if (index >= model_->GetItemCount()) {
+ return false;
+ }
if ((model_->GetTypeAt(index) == menus::MenuModel::TYPE_RADIO) &&
(model_->GetCommandIdAt(index) == COMMAND_ID_IME_PROPERTIES)) {
- *property_index = model_->GetGroupIdAt(index);
- return true;
+ const int tmp_property_index = model_->GetGroupIdAt(index);
+ const ImePropertyList& property_list
+ = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties();
+ if (tmp_property_index < static_cast<int>(property_list.size())) {
+ *property_index = tmp_property_index;
+ return true;
+ }
}
return false;
}
@@ -451,6 +463,9 @@ bool LanguageMenuButton::GetPropertyIndex(
bool LanguageMenuButton::IndexPointsToConfigureImeMenuItem(int index) const {
DCHECK_GE(index, 0);
DCHECK(model_.get());
+ if (index >= model_->GetItemCount()) {
+ return false;
+ }
return ((model_->GetTypeAt(index) == menus::MenuModel::TYPE_RADIO) &&
(model_->GetCommandIdAt(index) == COMMAND_ID_CONFIGURE_IME));