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

Unified Diff: device/hid/hid_connection_win.cc

Issue 943783003: Pad HID output reports on Windows to the maximum output report size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « device/hid/hid_connection.cc ('k') | extensions/browser/api/hid/hid_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection_win.cc
diff --git a/device/hid/hid_connection_win.cc b/device/hid/hid_connection_win.cc
index b453c2f5e78e01f05d164e23604981e63af5a93a..ecf4a0a19558ca863c49ac69373c235c6d93eb18 100644
--- a/device/hid/hid_connection_win.cc
+++ b/device/hid/hid_connection_win.cc
@@ -137,8 +137,19 @@ void HidConnectionWin::PlatformRead(
void HidConnectionWin::PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
const WriteCallback& callback) {
- // The Windows API always wants either a report ID (if supported) or
- // zero at the front of every output report.
+ size_t expected_size = device_info()->max_output_report_size() + 1;
+ DCHECK(size <= expected_size);
+ // The Windows API always wants either a report ID (if supported) or zero at
+ // the front of every output report and requires that the buffer be equal to
Ken Rockot(use gerrit already) 2015/02/20 02:31:46 nit: "requires that the buffer be equal to"
+ // the maximum output report supported by this collection.
+ if (size < expected_size) {
+ scoped_refptr<net::IOBuffer> tmp_buffer = new net::IOBuffer(
+ base::checked_cast<int>(expected_size));
+ memcpy(tmp_buffer->data(), buffer->data(), size);
+ memset(tmp_buffer->data() + size, 0, expected_size - size);
+ buffer = tmp_buffer;
+ size = expected_size;
+ }
scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
buffer, base::Bind(&HidConnectionWin::OnWriteComplete, this, callback)));
transfers_.insert(transfer);
« no previous file with comments | « device/hid/hid_connection.cc ('k') | extensions/browser/api/hid/hid_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698