summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--device/hid/hid_connection_linux.cc2
-rw-r--r--device/hid/hid_connection_unittest.cc9
-rw-r--r--device/hid/hid_connection_win.cc9
-rw-r--r--device/hid/hid_device_info.h6
-rw-r--r--device/hid/hid_report_descriptor.cc30
-rw-r--r--device/hid/hid_report_descriptor.h6
-rw-r--r--device/hid/hid_report_descriptor_unittest.cc12
-rw-r--r--device/hid/hid_service_mac.cc7
8 files changed, 44 insertions, 37 deletions
diff --git a/device/hid/hid_connection_linux.cc b/device/hid/hid_connection_linux.cc
index 021d301..907f79b 100644
--- a/device/hid/hid_connection_linux.cc
+++ b/device/hid/hid_connection_linux.cc
@@ -111,7 +111,7 @@ void HidConnectionLinux::PlatformGetFeatureReport(
const ReadCallback& callback) {
// The first byte of the destination buffer is the report ID being requested
// and is overwritten by the feature report.
- DCHECK_GT(device_info().max_feature_report_size, 0);
+ DCHECK_GT(device_info().max_feature_report_size, 0u);
scoped_refptr<net::IOBufferWithSize> buffer(
new net::IOBufferWithSize(device_info().max_feature_report_size + 1));
buffer->data()[0] = report_id;
diff --git a/device/hid/hid_connection_unittest.cc b/device/hid/hid_connection_unittest.cc
index 5654fc0..5e48ef9 100644
--- a/device/hid/hid_connection_unittest.cc
+++ b/device/hid/hid_connection_unittest.cc
@@ -158,10 +158,11 @@ TEST_F(HidConnectionTest, ReadWrite) {
scoped_refptr<HidConnection> conn = connect_callback.WaitForConnection();
ASSERT_TRUE(conn.get());
- for (int i = 0; i < 8; ++i) {
- scoped_refptr<IOBufferWithSize> buffer(new IOBufferWithSize(9));
+ const char kBufferSize = 9;
+ for (char i = 0; i < 8; ++i) {
+ scoped_refptr<IOBufferWithSize> buffer(new IOBufferWithSize(kBufferSize));
buffer->data()[0] = 0;
- for (int j = 1; j < buffer->size(); ++j) {
+ for (char j = 1; j < kBufferSize; ++j) {
buffer->data()[j] = i + j - 1;
}
@@ -174,7 +175,7 @@ TEST_F(HidConnectionTest, ReadWrite) {
ASSERT_TRUE(read_callback.WaitForResult());
ASSERT_EQ(9UL, read_callback.size());
ASSERT_EQ(0, read_callback.buffer()->data()[0]);
- for (int j = 1; j < buffer->size(); ++j) {
+ for (char j = 1; j < kBufferSize; ++j) {
ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]);
}
}
diff --git a/device/hid/hid_connection_win.cc b/device/hid/hid_connection_win.cc
index a8414da..1783092 100644
--- a/device/hid/hid_connection_win.cc
+++ b/device/hid/hid_connection_win.cc
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/files/file.h"
#include "base/message_loop/message_loop.h"
+#include "base/numerics/safe_conversions.h"
#include "base/profiler/scoped_profile.h"
#include "base/win/object_watcher.h"
@@ -135,8 +136,8 @@ void HidConnectionWin::PlatformRead(
const HidConnection::ReadCallback& callback) {
// Windows will always include the report ID (including zero if report IDs
// are not in use) in the buffer.
- scoped_refptr<net::IOBufferWithSize> buffer =
- new net::IOBufferWithSize(device_info().max_input_report_size + 1);
+ scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
+ base::checked_cast<int>(device_info().max_input_report_size + 1));
scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
buffer,
base::Bind(&HidConnectionWin::OnReadComplete, this, buffer, callback)));
@@ -167,8 +168,8 @@ void HidConnectionWin::PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id,
const ReadCallback& callback) {
// The first byte of the destination buffer is the report ID being requested.
- scoped_refptr<net::IOBufferWithSize> buffer =
- new net::IOBufferWithSize(device_info().max_feature_report_size + 1);
+ scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
+ base::checked_cast<int>(device_info().max_feature_report_size + 1));
buffer->data()[0] = report_id;
scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
diff --git a/device/hid/hid_device_info.h b/device/hid/hid_device_info.h
index f4c9a0b..bb1cc04 100644
--- a/device/hid/hid_device_info.h
+++ b/device/hid/hid_device_info.h
@@ -36,9 +36,9 @@ struct HidDeviceInfo {
// Top-Level Collections information.
std::vector<HidCollectionInfo> collections;
bool has_report_id;
- uint16_t max_input_report_size;
- uint16_t max_output_report_size;
- uint16_t max_feature_report_size;
+ size_t max_input_report_size;
+ size_t max_output_report_size;
+ size_t max_feature_report_size;
};
} // namespace device
diff --git a/device/hid/hid_report_descriptor.cc b/device/hid/hid_report_descriptor.cc
index d8031d3..331186c 100644
--- a/device/hid/hid_report_descriptor.cc
+++ b/device/hid/hid_report_descriptor.cc
@@ -29,9 +29,9 @@ HidReportDescriptor::~HidReportDescriptor() {}
void HidReportDescriptor::GetDetails(
std::vector<HidCollectionInfo>* top_level_collections,
bool* has_report_id,
- uint16_t* max_input_report_size,
- uint16_t* max_output_report_size,
- uint16_t* max_feature_report_size) {
+ size_t* max_input_report_size,
+ size_t* max_output_report_size,
+ size_t* max_feature_report_size) {
DCHECK(top_level_collections);
DCHECK(max_input_report_size);
DCHECK(max_output_report_size);
@@ -45,16 +45,16 @@ void HidReportDescriptor::GetDetails(
// Global tags data:
HidUsageAndPage::Page current_usage_page = HidUsageAndPage::kPageUndefined;
- uint16_t current_report_count = 0;
- uint16_t cached_report_count = 0;
- uint16_t current_report_size = 0;
- uint16_t cached_report_size = 0;
- uint16_t current_input_report_size = 0;
- uint16_t current_output_report_size = 0;
- uint16_t current_feature_report_size = 0;
+ size_t current_report_count = 0;
+ size_t cached_report_count = 0;
+ size_t current_report_size = 0;
+ size_t cached_report_size = 0;
+ size_t current_input_report_size = 0;
+ size_t current_output_report_size = 0;
+ size_t current_feature_report_size = 0;
// Local tags data:
- uint16_t current_usage = 0;
+ uint32_t current_usage = 0;
for (std::vector<linked_ptr<HidReportDescriptorItem> >::const_iterator
items_iter = items().begin();
@@ -65,10 +65,12 @@ void HidReportDescriptor::GetDetails(
switch (current_item->tag()) {
// Main tags:
case HidReportDescriptorItem::kTagCollection:
- if (!current_item->parent()) {
+ if (!current_item->parent() &&
+ (current_usage <= std::numeric_limits<uint16_t>::max())) {
// This is a top-level collection.
HidCollectionInfo collection;
- collection.usage = HidUsageAndPage(current_usage, current_usage_page);
+ collection.usage = HidUsageAndPage(
+ static_cast<uint16_t>(current_usage), current_usage_page);
top_level_collections->push_back(collection);
}
break;
@@ -87,7 +89,7 @@ void HidReportDescriptor::GetDetails(
// Global tags:
case HidReportDescriptorItem::kTagUsagePage:
current_usage_page =
- (HidUsageAndPage::Page)current_item->GetShortData();
+ static_cast<HidUsageAndPage::Page>(current_item->GetShortData());
break;
case HidReportDescriptorItem::kTagReportId:
if (top_level_collections->size() > 0) {
diff --git a/device/hid/hid_report_descriptor.h b/device/hid/hid_report_descriptor.h
index 1719e94..61412c2 100644
--- a/device/hid/hid_report_descriptor.h
+++ b/device/hid/hid_report_descriptor.h
@@ -29,9 +29,9 @@ class HidReportDescriptor {
// together with max report sizes
void GetDetails(std::vector<HidCollectionInfo>* top_level_collections,
bool* has_report_id,
- uint16_t* max_input_report_size,
- uint16_t* max_output_report_size,
- uint16_t* max_feature_report_size);
+ size_t* max_input_report_size,
+ size_t* max_output_report_size,
+ size_t* max_feature_report_size);
private:
std::vector<linked_ptr<HidReportDescriptorItem> > items_;
diff --git a/device/hid/hid_report_descriptor_unittest.cc b/device/hid/hid_report_descriptor_unittest.cc
index dc0f96a..312d6f8 100644
--- a/device/hid/hid_report_descriptor_unittest.cc
+++ b/device/hid/hid_report_descriptor_unittest.cc
@@ -298,18 +298,18 @@ class HidReportDescriptorTest : public testing::Test {
void ValidateDetails(
const std::vector<HidCollectionInfo>& expected_collections,
const bool expected_has_report_id,
- const uint16_t expected_max_input_report_size,
- const uint16_t expected_max_output_report_size,
- const uint16_t expected_max_feature_report_size,
+ const size_t expected_max_input_report_size,
+ const size_t expected_max_output_report_size,
+ const size_t expected_max_feature_report_size,
const uint8_t* bytes,
size_t size) {
descriptor_ = new HidReportDescriptor(bytes, size);
std::vector<HidCollectionInfo> actual_collections;
bool actual_has_report_id;
- uint16_t actual_max_input_report_size;
- uint16_t actual_max_output_report_size;
- uint16_t actual_max_feature_report_size;
+ size_t actual_max_input_report_size;
+ size_t actual_max_output_report_size;
+ size_t actual_max_feature_report_size;
descriptor_->GetDetails(&actual_collections,
&actual_has_report_id,
&actual_max_input_report_size,
diff --git a/device/hid/hid_service_mac.cc b/device/hid/hid_service_mac.cc
index 4723668..6e091a85 100644
--- a/device/hid/hid_service_mac.cc
+++ b/device/hid/hid_service_mac.cc
@@ -106,8 +106,11 @@ void GetCollectionInfos(IOHIDDeviceRef device,
HidCollectionInfo collection_info;
HidUsageAndPage::Page page = static_cast<HidUsageAndPage::Page>(
IOHIDElementGetUsagePage(collection));
- uint16_t usage = IOHIDElementGetUsage(collection);
- collection_info.usage = HidUsageAndPage(usage, page);
+ uint32_t usage = IOHIDElementGetUsage(collection);
+ if (usage > std::numeric_limits<uint16_t>::max())
+ continue;
+ collection_info.usage =
+ HidUsageAndPage(static_cast<uint16_t>(usage), page);
// Explore children recursively and retrieve their report IDs
GetReportIds(collection, &collection_info.report_ids);
if (collection_info.report_ids.size() > 0) {