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

Unified Diff: chrome/browser/extensions/api/usb/usb_device_resource.cc

Issue 10826273: Allocate a one-byte IOBuffer for transfers that are zero-length. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "impedance". Created 8 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/usb/usb_device_resource.cc
diff --git a/chrome/browser/extensions/api/usb/usb_device_resource.cc b/chrome/browser/extensions/api/usb/usb_device_resource.cc
index da8efdf499c5239c2131ab0b2e8ea709b6bd1ec1..5193180f479b7c12729c431aa437aa9a235f9959 100644
--- a/chrome/browser/extensions/api/usb/usb_device_resource.cc
+++ b/chrome/browser/extensions/api/usb/usb_device_resource.cc
@@ -111,17 +111,18 @@ static bool GetTransferSize(const T& input, size_t* output) {
template<class T>
static scoped_refptr<net::IOBuffer> CreateBufferForTransfer(const T& input) {
size_t size = 0;
- if (!GetTransferSize(input, &size)) {
+ if (!GetTransferSize(input, &size))
return NULL;
- }
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size);
- if (!input.data.get()) {
+ // Allocate a |size|-bytes buffer, or a one-byte buffer if |size| is 0. This
+ // is due to an impedance mismatch between IOBuffer and URBs. An IOBuffer
+ // cannot represent a zero-length buffer, while an URB can.
+ scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(std::max(
+ static_cast<size_t>(1), size));
+ if (!input.data.get())
return buffer;
- }
memcpy(buffer->data(), input.data->data(), size);
-
return buffer;
}
« 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