Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8145)

Unified Diff: chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc
diff --git a/chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc b/chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc
index 28efc762c3bb268f02edfe93b1278ad6087cf73b..79edccd40eceab121d01dcd904e3b2bf08fc53af 100644
--- a/chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc
+++ b/chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc
@@ -30,14 +30,18 @@ std::unique_ptr<base::Value> SnapshotHistogramToValue(
std::unique_ptr<base::SampleCountIterator> iterator = samples->Iterator();
while (!iterator->Done()) {
base::HistogramBase::Sample min;
- base::HistogramBase::Sample max;
+ int64_t max;
base::HistogramBase::Count count;
iterator->Get(&min, &max, &count);
std::unique_ptr<base::DictionaryValue> bucket =
base::MakeUnique<base::DictionaryValue>();
bucket->SetInteger("min", min);
- bucket->SetInteger("max", max);
+ // Note: DictionaryValue does not support 64-bit integer values. The static
+ // cast below is OK in this case because none of the histograms passed to
+ // this function should be logging MaxInt32 as a sparse histogram bucket,
+ // which is the only case max will exceed 32-bit range.
+ bucket->SetInteger("max", static_cast<int>(max));
Ilya Sherman 2017/05/02 21:37:49 nit: Could this be a checked_cast?
Alexei Svitkine (slow) 2017/05/03 15:21:53 Done.
bucket->SetInteger("count", count);
values->Append(std::move(bucket));

Powered by Google App Engine
This is Rietveld 408576698