Fix some 64-bit to 32-bit implicit conversions in sql.
Found with -Wshorten-64-to-32.
../../sql/initialization.cc(21,59): warning: implicit conversion loses integer precision: 'long long' to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.TenMinutes", used / 1024);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
../..\base/metrics/histogram_macros.h(364,11): note: expanded from macro 'UMA_HISTOGRAM_COUNTS'
name, sample, 1, 1000000, 50)
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros.h(189,15): note: expanded from macro 'UMA_HISTOGRAM_CUSTOM_COUNTS'
name, sample, min, max, bucket_count, \
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(128,19): note: expanded from macro 'INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG'
name, Add(sample), \
~~~ ^~~~~~
../..\base/metrics/histogram_macros_internal.h(120,27): note: expanded from macro 'STATIC_HISTOGRAM_POINTER_BLOCK'
histogram_add_method_invocation, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(104,24): note: expanded from macro 'HISTOGRAM_POINTER_USE'
histogram_pointer->histogram_add_method_invocation; \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../sql/initialization.cc(26,56): warning: implicit conversion loses integer precision: 'long long' to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneHour", used / 1024);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
../..\base/metrics/histogram_macros.h(364,11): note: expanded from macro 'UMA_HISTOGRAM_COUNTS'
name, sample, 1, 1000000, 50)
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros.h(189,15): note: expanded from macro 'UMA_HISTOGRAM_CUSTOM_COUNTS'
name, sample, min, max, bucket_count, \
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(128,19): note: expanded from macro 'INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG'
name, Add(sample), \
~~~ ^~~~~~
../..\base/metrics/histogram_macros_internal.h(120,27): note: expanded from macro 'STATIC_HISTOGRAM_POINTER_BLOCK'
histogram_add_method_invocation, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(104,24): note: expanded from macro 'HISTOGRAM_POINTER_USE'
histogram_pointer->histogram_add_method_invocation; \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../sql/initialization.cc(31,55): warning: implicit conversion loses integer precision: 'long long' to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneDay", used / 1024);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
../..\base/metrics/histogram_macros.h(364,11): note: expanded from macro 'UMA_HISTOGRAM_COUNTS'
name, sample, 1, 1000000, 50)
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros.h(189,15): note: expanded from macro 'UMA_HISTOGRAM_CUSTOM_COUNTS'
name, sample, min, max, bucket_count, \
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(128,19): note: expanded from macro 'INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG'
name, Add(sample), \
~~~ ^~~~~~
../..\base/metrics/histogram_macros_internal.h(120,27): note: expanded from macro 'STATIC_HISTOGRAM_POINTER_BLOCK'
histogram_add_method_invocation, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(104,24): note: expanded from macro 'HISTOGRAM_POINTER_USE'
histogram_pointer->histogram_add_method_invocation; \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../sql/initialization.cc(36,56): warning: implicit conversion loses integer precision: 'long long' to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneWeek", used / 1024);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
../..\base/metrics/histogram_macros.h(364,11): note: expanded from macro 'UMA_HISTOGRAM_COUNTS'
name, sample, 1, 1000000, 50)
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros.h(189,15): note: expanded from macro 'UMA_HISTOGRAM_CUSTOM_COUNTS'
name, sample, min, max, bucket_count, \
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(128,19): note: expanded from macro 'INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG'
name, Add(sample), \
~~~ ^~~~~~
../..\base/metrics/histogram_macros_internal.h(120,27): note: expanded from macro 'STATIC_HISTOGRAM_POINTER_BLOCK'
histogram_add_method_invocation, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(104,24): note: expanded from macro 'HISTOGRAM_POINTER_USE'
histogram_pointer->histogram_add_method_invocation; \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../sql/statement.cc(167,40): warning: implicit conversion loses integer precision: 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type' (aka 'unsigned long long') to 'int' [-Wshorten-64-to-32]
val.size(), SQLITE_TRANSIENT));
~~~~^~~~~~
../../sql/database.cc(346,24): warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
histogram->Add(sample);
~~~ ^~~~~~
../../sql/database.cc(347,45): warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
UMA_HISTOGRAM_COUNTS("Sqlite.SizeKB", sample);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
../..\base/metrics/histogram_macros.h(364,11): note: expanded from macro 'UMA_HISTOGRAM_COUNTS'
name, sample, 1, 1000000, 50)
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros.h(189,15): note: expanded from macro 'UMA_HISTOGRAM_CUSTOM_COUNTS'
name, sample, min, max, bucket_count, \
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(128,19): note: expanded from macro 'INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG'
name, Add(sample), \
~~~ ^~~~~~
../..\base/metrics/histogram_macros_internal.h(120,27): note: expanded from macro 'STATIC_HISTOGRAM_POINTER_BLOCK'
histogram_add_method_invocation, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../..\base/metrics/histogram_macros_internal.h(104,24): note: expanded from macro 'HISTOGRAM_POINTER_USE'
histogram_pointer->histogram_add_method_invocation; \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../sql/database.cc(1810,20): warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'base::HistogramBase::Sample' (aka 'int') [-Wshorten-64-to-32]
histogram->Add(sample);
~~~ ^~~~~~
BUG=588506
Change-Id: I5b0fb4d1913301a64af178924f98c22e7811b359
Reviewed-on: https://chromium-review.googlesource.com/1188758
Reviewed-by: Victor Costan <[email protected]>
Commit-Queue: Victor Costan <[email protected]>
Cr-Commit-Position: refs/heads/master@{#586906}
diff --git a/sql/database.cc b/sql/database.cc
index ffe7c6b..0db54f2 100644
--- a/sql/database.cc
+++ b/sql/database.cc
@@ -21,6 +21,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/no_destructor.h"
+#include "base/numerics/safe_conversions.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
@@ -337,7 +338,7 @@
if (!histogram_tag_.empty()) {
int64_t size_64 = 0;
if (base::GetFileSize(path, &size_64)) {
- size_t sample = static_cast<size_t>(size_64 / 1024);
+ int sample = base::saturated_cast<int>(size_64 / 1024);
std::string full_histogram_name = "Sqlite.SizeKB." + histogram_tag_;
base::HistogramBase* histogram = base::Histogram::FactoryGet(
full_histogram_name, 1, 1000000, 50,
@@ -1794,8 +1795,7 @@
histogram_tag_ = tag;
}
-void Database::AddTaggedHistogram(const std::string& name,
- size_t sample) const {
+void Database::AddTaggedHistogram(const std::string& name, int sample) const {
if (histogram_tag_.empty())
return;