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

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: Address comments. 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
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | components/metrics/histogram_encoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7568aae2420f258bb1d22d5366709b7afe375617 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
@@ -10,6 +10,7 @@
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
+#include "base/numerics/safe_conversions.h"
#include "base/task_scheduler/task_scheduler.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
@@ -30,14 +31,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 checked
+ // 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", base::checked_cast<int>(max));
bucket->SetInteger("count", count);
values->Append(std::move(bucket));
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | components/metrics/histogram_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698