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

Unified Diff: ppapi/shared_impl/ppb_gamepad_shared.cc

Issue 1136463002: Pass correct length value in WebGamepads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use std::min for comparison Created 5 years, 7 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 | « ppapi/examples/gamepad/gamepad.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/ppb_gamepad_shared.cc
diff --git a/ppapi/shared_impl/ppb_gamepad_shared.cc b/ppapi/shared_impl/ppb_gamepad_shared.cc
index 7aa752a8aab561a2d8eba127baed419c77e5ed5d..c819d24d5d3e54ee0331ee5705298db7d7806c23 100644
--- a/ppapi/shared_impl/ppb_gamepad_shared.cc
+++ b/ppapi/shared_impl/ppb_gamepad_shared.cc
@@ -4,14 +4,18 @@
#include "ppapi/shared_impl/ppb_gamepad_shared.h"
+#include <algorithm>
+
#include "base/basictypes.h"
namespace ppapi {
void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data,
PP_GamepadsSampleData* output_data) {
- output_data->length = webkit_data.length;
- for (unsigned i = 0; i < webkit_data.length; ++i) {
+ size_t length = std::min(WebKitGamepads::kItemsLengthCap,
+ (const size_t)webkit_data.length);
bbudge 2015/05/08 17:31:52 Use C++ style cast. Also, you could avoid a cast b
arajp 2015/05/11 10:40:40 Changed to C++ style cast. Changing length to uint
bbudge 2015/05/11 11:21:29 Would using 'unsigned' to match WebKitGamepads hel
arajp 2015/05/11 11:29:20 Done.
+ output_data->length = static_cast<uint32_t>(length);
+ for (unsigned i = 0; i < length; ++i) {
PP_GamepadSampleData& output_pad = output_data->items[i];
const WebKitGamepad& webkit_pad = webkit_data.items[i];
output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE;
« no previous file with comments | « ppapi/examples/gamepad/gamepad.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698