From ce21d4a9afd215f8c006b91253cec5ab06b60530 Mon Sep 17 00:00:00 2001 From: "jeremy@chromium.org" Date: Sun, 8 Nov 2009 12:22:53 +0000 Subject: Make sure we don't get an outside array element. BUG=None TEST=covered by unit_tests. Review URL: http://codereview.chromium.org/343076 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31401 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/importer/importer.h | 2 +- chrome/browser/importer/importer_list.cc | 10 +++++----- chrome/browser/importer/importer_list.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'chrome/browser/importer') diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index ee832bd..a8fe226 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -249,7 +249,7 @@ class ImporterHost : public base::RefCountedThreadSafe, void ImportItemEnded(ImportItem item); void ImportEnded(); - int GetAvailableProfileCount() { + int GetAvailableProfileCount() const { return importer_list_.GetAvailableProfileCount(); } diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc index 4f3c815..c705b51 100644 --- a/chrome/browser/importer/importer_list.cc +++ b/chrome/browser/importer/importer_list.cc @@ -76,24 +76,24 @@ Importer* ImporterList::CreateImporterByType(ProfileType type) { return NULL; } -int ImporterList::GetAvailableProfileCount() { +int ImporterList::GetAvailableProfileCount() const { return static_cast(source_profiles_.size()); } std::wstring ImporterList::GetSourceProfileNameAt(int index) const { - DCHECK(index < static_cast(source_profiles_.size())); + DCHECK(index >=0 && index < GetAvailableProfileCount()); return source_profiles_[index]->description; } const ProfileInfo& ImporterList::GetSourceProfileInfoAt(int index) const { - DCHECK(index < static_cast(source_profiles_.size())); + DCHECK(index >=0 && index < GetAvailableProfileCount()); return *source_profiles_[index]; } const ProfileInfo& ImporterList::GetSourceProfileInfoForBrowserType( int browser_type) const { - int size = source_profiles_.size(); - for (int i = 0; i < size; i++) { + int count = GetAvailableProfileCount(); + for (int i = 0; i < count; ++i) { if (source_profiles_[i]->browser_type == browser_type) return *source_profiles_[i]; } diff --git a/chrome/browser/importer/importer_list.h b/chrome/browser/importer/importer_list.h index 4574a29..9619bb9 100644 --- a/chrome/browser/importer/importer_list.h +++ b/chrome/browser/importer/importer_list.h @@ -44,7 +44,7 @@ class ImporterList { Importer* CreateImporterByType(ProfileType type); // Returns the number of different browser profiles you can import from. - int GetAvailableProfileCount(); + int GetAvailableProfileCount() const; // Returns the name of the profile at the 'index' slot. The profiles are // ordered such that the profile at index 0 is the likely default browser. -- cgit v1.1