Support 32-bit subversion fields in base::Version.
BUG=464610
TEST=base_unittests
Review URL: https://codereview.chromium.org/985573003
Cr-Commit-Position: refs/heads/master@{#319806}
diff --git a/base/version.cc b/base/version.cc
index 933356e..ede8a458 100644
--- a/base/version.cc
+++ b/base/version.cc
@@ -23,7 +23,7 @@
// is the resulting integer vector. Function returns true if all numbers were
// parsed successfully, false otherwise.
bool ParseVersionNumbers(const std::string& version_str,
- std::vector<uint16>* parsed) {
+ std::vector<uint32_t>* parsed) {
std::vector<std::string> numbers;
SplitString(version_str, '.', &numbers);
if (numbers.empty())
@@ -33,22 +33,18 @@
it != numbers.end(); ++it) {
if (StartsWithASCII(*it, "+", false))
return false;
- int num;
- if (!StringToInt(*it, &num))
- return false;
-
- if (num < 0)
- return false;
-
- const uint16 max = 0xFFFF;
- if (num > max)
+ unsigned int num;
+ if (!StringToUint(*it, &num))
return false;
// This throws out leading zeros for the first item only.
- if (it == numbers.begin() && IntToString(num) != *it)
+ if (it == numbers.begin() && UintToString(num) != *it)
return false;
- parsed->push_back(static_cast<uint16>(num));
+ // StringToUint returns unsigned int but Version fields are uint32_t.
+ static_assert(sizeof (uint32_t) == sizeof (unsigned int),
+ "uint32_t must be same as unsigned int");
+ parsed->push_back(num);
}
return true;
}
@@ -56,8 +52,8 @@
// Compares version components in |components1| with components in
// |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to,
// or greater than |components2|, respectively.
-int CompareVersionComponents(const std::vector<uint16>& components1,
- const std::vector<uint16>& components2) {
+int CompareVersionComponents(const std::vector<uint32_t>& components1,
+ const std::vector<uint32_t>& components2) {
const size_t count = std::min(components1.size(), components2.size());
for (size_t i = 0; i < count; ++i) {
if (components1[i] > components2[i])
@@ -88,7 +84,7 @@
}
Version::Version(const std::string& version_str) {
- std::vector<uint16> parsed;
+ std::vector<uint32_t> parsed;
if (!ParseVersionNumbers(version_str, &parsed))
return;
@@ -127,7 +123,7 @@
return CompareTo(version);
}
- std::vector<uint16> parsed;
+ std::vector<uint32_t> parsed;
const bool success = ParseVersionNumbers(
wildcard_string.substr(0, wildcard_string.length() - 2), &parsed);
DCHECK(success);
diff --git a/base/version.h b/base/version.h
index b3012eb9..814acaa 100644
--- a/base/version.h
+++ b/base/version.h
@@ -5,6 +5,7 @@
#ifndef BASE_VERSION_H_
#define BASE_VERSION_H_
+#include <stdint.h>
#include <string>
#include <vector>
@@ -57,10 +58,10 @@
// Return the string representation of this version.
const std::string GetString() const;
- const std::vector<uint16>& components() const { return components_; }
+ const std::vector<uint32_t>& components() const { return components_; }
private:
- std::vector<uint16> components_;
+ std::vector<uint32_t> components_;
};
} // namespace base
diff --git a/base/version_unittest.cc b/base/version_unittest.cc
index 46d8255d..f40ed27 100644
--- a/base/version_unittest.cc
+++ b/base/version_unittest.cc
@@ -31,39 +31,44 @@
static const struct version_string {
const char* input;
size_t parts;
+ uint32_t firstpart;
bool success;
} cases[] = {
- {"", 0, false},
- {" ", 0, false},
- {"\t", 0, false},
- {"\n", 0, false},
- {" ", 0, false},
- {".", 0, false},
- {" . ", 0, false},
- {"0", 1, true},
- {"0.", 0, false},
- {"0.0", 2, true},
- {"65537.0", 0, false},
- {"-1.0", 0, false},
- {"1.-1.0", 0, false},
- {"1,--1.0", 0, false},
- {"+1.0", 0, false},
- {"1.+1.0", 0, false},
- {"1+1.0", 0, false},
- {"++1.0", 0, false},
- {"1.0a", 0, false},
- {"1.2.3.4.5.6.7.8.9.0", 10, true},
- {"02.1", 0, false},
- {"0.01", 2, true},
- {"f.1", 0, false},
- {"15.007.20011", 3, true},
+ {"", 0, 0, false},
+ {" ", 0, 0, false},
+ {"\t", 0, 0, false},
+ {"\n", 0, 0, false},
+ {" ", 0, 0, false},
+ {".", 0, 0, false},
+ {" . ", 0, 0, false},
+ {"0", 1, 0, true},
+ {"0.", 0, 0, false},
+ {"0.0", 2, 0, true},
+ {"4294967295.0", 2, 4294967295, true},
+ {"4294967296.0", 0, 0, false},
+ {"-1.0", 0, 0, false},
+ {"1.-1.0", 0, 0, false},
+ {"1,--1.0", 0, 0, false},
+ {"+1.0", 0, 0, false},
+ {"1.+1.0", 0, 0, false},
+ {"1+1.0", 0, 0, false},
+ {"++1.0", 0, 0, false},
+ {"1.0a", 0, 0, false},
+ {"1.2.3.4.5.6.7.8.9.0", 10, 1, true},
+ {"02.1", 0, 0, false},
+ {"0.01", 2, 0, true},
+ {"f.1", 0, 0, false},
+ {"15.007.20011", 3, 15, true},
+ {"15.5.28.130162", 4, 15, true},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
Version version(cases[i].input);
EXPECT_EQ(cases[i].success, version.IsValid());
- if (cases[i].success)
+ if (cases[i].success) {
EXPECT_EQ(cases[i].parts, version.components().size());
+ EXPECT_EQ(cases[i].firstpart, version.components()[0]);
+ }
}
}
@@ -84,6 +89,7 @@
{"1.0.0", "1.0", 0},
{"1.0.3", "1.0.20", -1},
{"11.0.10", "15.007.20011", -1},
+ {"11.0.10", "15.5.28.130162", -1},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
Version lhs(cases[i].lhs);
diff --git a/chrome/browser/component_updater/pepper_flash_component_installer.cc b/chrome/browser/component_updater/pepper_flash_component_installer.cc
index 529a036..7fbe733 100644
--- a/chrome/browser/component_updater/pepper_flash_component_installer.cc
+++ b/chrome/browser/component_updater/pepper_flash_component_installer.cc
@@ -107,7 +107,7 @@
content::PepperPluginInfo* plugin_info) {
if (!flash_version.IsValid())
return false;
- const std::vector<uint16_t> ver_nums = flash_version.components();
+ const std::vector<uint32_t> ver_nums = flash_version.components();
if (ver_nums.size() < 3)
return false;
diff --git a/chrome/browser/component_updater/sw_reporter_installer_win.cc b/chrome/browser/component_updater/sw_reporter_installer_win.cc
index c0b877e..acb6280 100644
--- a/chrome/browser/component_updater/sw_reporter_installer_win.cc
+++ b/chrome/browser/component_updater/sw_reporter_installer_win.cc
@@ -121,14 +121,14 @@
// The major version for X.Y.Z is X*256^3+Y*256+Z. If there are additional
// components, only the first three count, and if there are less than 3, the
// missing values are just replaced by zero. So 1 is equivalent 1.0.0.
- DCHECK_LT(version.components()[0], 0x100);
+ DCHECK_LT(version.components()[0], 0x100U);
uint32_t major_version = 0x1000000 * version.components()[0];
if (version.components().size() >= 2) {
- DCHECK_LT(version.components()[1], 0x10000);
+ DCHECK_LT(version.components()[1], 0x10000U);
major_version += 0x100 * version.components()[1];
}
if (version.components().size() >= 3) {
- DCHECK_LT(version.components()[2], 0x100);
+ DCHECK_LT(version.components()[2], 0x100U);
major_version += version.components()[2];
}
UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MajorVersion", major_version);
diff --git a/chrome/browser/google/google_update_win_unittest.cc b/chrome/browser/google/google_update_win_unittest.cc
index 82f2e69..97498e4b 100644
--- a/chrome/browser/google/google_update_win_unittest.cc
+++ b/chrome/browser/google/google_update_win_unittest.cc
@@ -344,7 +344,7 @@
// Compute a newer version.
base::Version current_version(CHROME_VERSION_STRING);
- new_version_ = base::StringPrintf(L"%hu.%hu.%hu.%hu",
+ new_version_ = base::StringPrintf(L"%u.%u.%u.%u",
current_version.components()[0],
current_version.components()[1],
current_version.components()[2] + 1,
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
index 4eca8af..1874299 100644
--- a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
@@ -122,13 +122,13 @@
UMALinuxGlibcVersion glibc_version_result = UMA_LINUX_GLIBC_NOT_PARSEABLE;
if (version.IsValid() && version.components().size() == 2) {
glibc_version_result = UMA_LINUX_GLIBC_UNKNOWN;
- int glibc_major_version = version.components()[0];
- int glibc_minor_version = version.components()[1];
+ uint32_t glibc_major_version = version.components()[0];
+ uint32_t glibc_minor_version = version.components()[1];
if (glibc_major_version == 2) {
// A constant to translate glibc 2.x minor versions to their
// equivalent UMALinuxGlibcVersion values.
const int kGlibcMinorVersionTranslationOffset = 11 - UMA_LINUX_GLIBC_2_11;
- int translated_glibc_minor_version =
+ uint32_t translated_glibc_minor_version =
glibc_minor_version - kGlibcMinorVersionTranslationOffset;
if (translated_glibc_minor_version >= UMA_LINUX_GLIBC_2_11) {
glibc_version_result =
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 799407a..a24d9563 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -502,7 +502,7 @@
NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path));
base::Version full_version(base::SysNSStringToUTF8(
[plist valueForKey:app_mode::kCFBundleShortVersionStringKey]));
- int major_version = 0;
+ uint32_t major_version = 0;
if (full_version.IsValid())
major_version = full_version.components()[0];
UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version);
diff --git a/chrome/installer/setup/install_worker.cc b/chrome/installer/setup/install_worker.cc
index d677f39..5f7449f 100644
--- a/chrome/installer/setup/install_worker.cc
+++ b/chrome/installer/setup/install_worker.cc
@@ -669,7 +669,7 @@
InstallUtil::GetCurrentDate(),
false);
- const std::vector<uint16>& version_components = new_version.components();
+ const std::vector<uint32_t>& version_components = new_version.components();
if (version_components.size() == 4) {
// Our version should be in major.minor.build.rev.
install_list->AddSetRegValueWorkItem(
diff --git a/chrome/installer/test/alternate_version_generator.cc b/chrome/installer/test/alternate_version_generator.cc
index 98c72cf..e50c293 100644
--- a/chrome/installer/test/alternate_version_generator.cc
+++ b/chrome/installer/test/alternate_version_generator.cc
@@ -111,7 +111,7 @@
static ChromeVersion FromString(const std::string& version_string) {
Version version(version_string);
DCHECK(version.IsValid());
- const std::vector<uint16>& c(version.components());
+ const std::vector<uint32_t>& c(version.components());
return ChromeVersion(static_cast<ULONGLONG>(c[0]) << 48 |
static_cast<ULONGLONG>(c[1]) << 32 |
static_cast<ULONGLONG>(c[2]) << 16 |
diff --git a/content/browser/gpu/gpu_data_manager_impl_private.cc b/content/browser/gpu/gpu_data_manager_impl_private.cc
index 06d083b..c0e3fd6 100644
--- a/content/browser/gpu/gpu_data_manager_impl_private.cc
+++ b/content/browser/gpu/gpu_data_manager_impl_private.cc
@@ -77,7 +77,7 @@
version_str = version_str.substr(0, pos);
Version os_version(version_str);
if (os_version.IsValid() && os_version.components().size() >= 2) {
- const std::vector<uint16>& version_numbers = os_version.components();
+ const std::vector<uint32_t>& version_numbers = os_version.components();
if (version_numbers[0] == 5)
sub_version = kWinXP;
else if (version_numbers[0] == 6 && version_numbers[1] == 0)
diff --git a/content/child/npapi/webplugin_delegate_impl_win.cc b/content/child/npapi/webplugin_delegate_impl_win.cc
index fffbe2e7..97d1f83 100644
--- a/content/child/npapi/webplugin_delegate_impl_win.cc
+++ b/content/child/npapi/webplugin_delegate_impl_win.cc
@@ -187,11 +187,11 @@
return std::wstring(info->Name, info->NameLength / sizeof(wchar_t));
}
-int GetPluginMajorVersion(const WebPluginInfo& plugin_info) {
+uint32_t GetPluginMajorVersion(const WebPluginInfo& plugin_info) {
Version plugin_version;
WebPluginInfo::CreateVersionFromString(plugin_info.version, &plugin_version);
- int major_version = 0;
+ uint32_t major_version = 0;
if (plugin_version.IsValid())
major_version = plugin_version.components()[0];
@@ -266,7 +266,7 @@
quirks_ |= PLUGIN_QUIRK_FAKE_WINDOW_FROM_POINT;
} else if (filename == kAcrobatReaderPlugin) {
// Check for the version number above or equal 9.
- int major_version = GetPluginMajorVersion(plugin_info);
+ uint32_t major_version = GetPluginMajorVersion(plugin_info);
if (major_version >= 9) {
quirks_ |= PLUGIN_QUIRK_DIE_AFTER_UNLOAD;
// 9.2 needs this.
@@ -300,7 +300,7 @@
// VLC hangs on NPP_Destroy if we call NPP_SetWindow with a null window
// handle
quirks_ |= PLUGIN_QUIRK_DONT_SET_NULL_WINDOW_HANDLE_ON_DESTROY;
- int major_version = GetPluginMajorVersion(plugin_info);
+ uint32_t major_version = GetPluginMajorVersion(plugin_info);
if (major_version == 0) {
// VLC 0.8.6d and 0.8.6e crash if multiple instances are created.
quirks_ |= PLUGIN_QUIRK_DONT_ALLOW_MULTIPLE_INSTANCES;