Commit 32bd0b6f authored by gdk@chromium.org's avatar gdk@chromium.org

Allocate a one-byte IOBuffer for transfers that are zero-length.

Since IOBuffers cannot be zero-length, but are used to back zero-length URBs,
allocate a single unused byte to back zero-length transfers.

BUG=128636
TEST=manual


Review URL: https://chromiumcodereview.appspot.com/10826273

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151323 0039d316-1c4b-4281-b951-d872f2087c98
parent e0ad71d9
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment