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

Side by Side Diff: blimp/net/blimp_stats.cc

Issue 2253513004: Fix off-by-one error in counter array sizing in BlimpStats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: spaces around plus Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « blimp/net/blimp_stats.h ('k') | blimp/net/stream_socket_connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/net/blimp_stats.h" 5 #include "blimp/net/blimp_stats.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace blimp { 9 namespace blimp {
10 10
11 // static 11 // static
12 base::LazyInstance<BlimpStats> BlimpStats::instance_ = 12 base::LazyInstance<BlimpStats> BlimpStats::instance_ =
13 LAZY_INSTANCE_INITIALIZER; 13 LAZY_INSTANCE_INITIALIZER;
14 14
15 // static 15 // static
16 BlimpStats* BlimpStats::GetInstance() { 16 BlimpStats* BlimpStats::GetInstance() {
17 return &instance_.Get(); 17 return &instance_.Get();
18 } 18 }
19 19
20 BlimpStats::BlimpStats() { 20 BlimpStats::BlimpStats() {
21 for (size_t i = 0; i < EVENT_TYPE_MAX; ++i) { 21 for (size_t i = 0; i <= EVENT_TYPE_MAX; ++i) {
22 base::subtle::NoBarrier_Store(&values_[i], 0); 22 base::subtle::NoBarrier_Store(&values_[i], 0);
23 } 23 }
24 } 24 }
25 25
26 BlimpStats::~BlimpStats() {} 26 BlimpStats::~BlimpStats() {}
27 27
28 void BlimpStats::Add(EventType type, base::subtle::Atomic32 amount) { 28 void BlimpStats::Add(EventType type, base::subtle::Atomic32 amount) {
29 if (amount < 0) { 29 if (amount < 0) {
30 DLOG(FATAL) << "Illegal negative stat value: type=" << type 30 DLOG(FATAL) << "Illegal negative stat value: type=" << type
31 << ", amount=" << amount << "."; 31 << ", amount=" << amount << ".";
32 return; 32 return;
33 } 33 }
34 34
35 base::subtle::NoBarrier_AtomicIncrement(&values_[type], amount); 35 base::subtle::NoBarrier_AtomicIncrement(&values_[type], amount);
36 } 36 }
37 37
38 base::subtle::Atomic32 BlimpStats::Get(EventType type) const { 38 base::subtle::Atomic32 BlimpStats::Get(EventType type) const {
39 return base::subtle::NoBarrier_Load(&values_[type]); 39 return base::subtle::NoBarrier_Load(&values_[type]);
40 } 40 }
41 41
42 } // namespace blimp 42 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blimp_stats.h ('k') | blimp/net/stream_socket_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698