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

Side by Side Diff: content/browser/gamepad/gamepad_provider.cc

Issue 1028673002: Fix use of arraysize in GamepadProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cmath> 5 #include <cmath>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void GamepadProvider::SendPauseHint(bool paused) { 164 void GamepadProvider::SendPauseHint(bool paused) {
165 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 165 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop());
166 if (data_fetcher_) 166 if (data_fetcher_)
167 data_fetcher_->PauseHint(paused); 167 data_fetcher_->PauseHint(paused);
168 } 168 }
169 169
170 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { 170 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const {
171 return connected_ == pad.connected && 171 return connected_ == pad.connected &&
172 axes_length_ == pad.axesLength && 172 axes_length_ == pad.axesLength &&
173 buttons_length_ == pad.buttonsLength && 173 buttons_length_ == pad.buttonsLength &&
174 memcmp(id_, pad.id, arraysize(id_)) == 0 && 174 memcmp(id_, pad.id, arraysize(id_) * sizeof(id_[0])) == 0 &&
inferno 2015/03/20 15:13:26 why not just sizeof(id_) ? same at all other place
kenrb 2015/03/20 15:53:02 I kind of like arraysize because it gives a compil
175 memcmp(mapping_, pad.mapping, arraysize(mapping_)) == 0; 175 memcmp(mapping_, pad.mapping,
176 arraysize(mapping_) * sizeof(mapping_[0])) == 0;
176 } 177 }
177 178
178 void GamepadProvider::PadState::SetPad(const WebGamepad& pad) { 179 void GamepadProvider::PadState::SetPad(const WebGamepad& pad) {
179 connected_ = pad.connected; 180 connected_ = pad.connected;
180 axes_length_ = pad.axesLength; 181 axes_length_ = pad.axesLength;
181 buttons_length_ = pad.buttonsLength; 182 buttons_length_ = pad.buttonsLength;
182 memcpy(id_, pad.id, arraysize(id_)); 183 memcpy(id_, pad.id, arraysize(id_) * sizeof(id_[0]));
183 memcpy(mapping_, pad.mapping, arraysize(mapping_)); 184 memcpy(mapping_, pad.mapping, arraysize(mapping_) * sizeof(mapping_[0]));
184 } 185 }
185 186
186 void GamepadProvider::PadState::SetDisconnected() { 187 void GamepadProvider::PadState::SetDisconnected() {
187 connected_ = false; 188 connected_ = false;
188 axes_length_ = 0; 189 axes_length_ = 0;
189 buttons_length_ = 0; 190 buttons_length_ = 0;
190 memset(id_, 0, arraysize(id_)); 191 memset(id_, 0, arraysize(id_) * sizeof(id_[0]));
191 memset(mapping_, 0, arraysize(mapping_)); 192 memset(mapping_, 0, arraysize(mapping_) * sizeof(mapping_[0]));
192 } 193 }
193 194
194 void GamepadProvider::PadState::AsWebGamepad(WebGamepad* pad) { 195 void GamepadProvider::PadState::AsWebGamepad(WebGamepad* pad) {
195 pad->connected = connected_; 196 pad->connected = connected_;
196 pad->axesLength = axes_length_; 197 pad->axesLength = axes_length_;
197 pad->buttonsLength = buttons_length_; 198 pad->buttonsLength = buttons_length_;
198 memcpy(pad->id, id_, arraysize(id_)); 199 memcpy(pad->id, id_, arraysize(id_) * sizeof(id_[0]));
199 memcpy(pad->mapping, mapping_, arraysize(mapping_)); 200 memcpy(pad->mapping, mapping_, arraysize(mapping_) * sizeof(mapping_[0]));
200 memset(pad->axes, 0, arraysize(pad->axes)); 201 memset(pad->axes, 0, arraysize(pad->axes) * sizeof(pad->axes[0]));
201 memset(pad->buttons, 0, arraysize(pad->buttons)); 202 memset(pad->buttons, 0, arraysize(pad->buttons) * sizeof(pad->buttons[0]));
202 } 203 }
203 204
204 void GamepadProvider::DoPoll() { 205 void GamepadProvider::DoPoll() {
205 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 206 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop());
206 DCHECK(have_scheduled_do_poll_); 207 DCHECK(have_scheduled_do_poll_);
207 have_scheduled_do_poll_ = false; 208 have_scheduled_do_poll_ = false;
208 209
209 bool changed; 210 bool changed;
210 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); 211 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
211 212
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 321 }
321 if (!had_gesture_before && ever_had_user_gesture_) { 322 if (!had_gesture_before && ever_had_user_gesture_) {
322 // Initialize pad_states_ for the first time. 323 // Initialize pad_states_ for the first time.
323 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { 324 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) {
324 pad_states_.get()[i].SetPad(pads.items[i]); 325 pad_states_.get()[i].SetPad(pads.items[i]);
325 } 326 }
326 } 327 }
327 } 328 }
328 329
329 } // namespace content 330 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698