diff options
author | pkasting <pkasting@chromium.org> | 2014-10-17 19:13:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-18 02:13:24 +0000 |
commit | 4c3b672cc2c1515b7e16cb535e1cd6e69e326607 (patch) | |
tree | ec3b7a1c3da0362644ce8c9851bece97bc965002 /device/hid/hid_report_descriptor.cc | |
parent | f5c85cf69f46e8231da8d292cbae29d5241ddadf (diff) | |
download | chromium_src-4c3b672cc2c1515b7e16cb535e1cd6e69e326607.zip chromium_src-4c3b672cc2c1515b7e16cb535e1cd6e69e326607.tar.gz chromium_src-4c3b672cc2c1515b7e16cb535e1cd6e69e326607.tar.bz2 |
Fix type truncation warnings in HID code.
GetShortData() and IOHIDElementGetUsage() both return uint32s, so raise the size
of various containing types to uint32.
I tried to look in the USB HID spec to see if any of the affected fields here
were limited to e.g. <2^16, meaning that it'd be safe to just cast down to the
existing uint16s instead, but I couldn't find any limits.
BUG=81439
TEST=none
Review URL: https://codereview.chromium.org/656583003
Cr-Commit-Position: refs/heads/master@{#300201}
Diffstat (limited to 'device/hid/hid_report_descriptor.cc')
-rw-r--r-- | device/hid/hid_report_descriptor.cc | 30 |
1 files changed, 16 insertions, 14 deletions
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) { |