diff options
author | Eric Roman <eroman@chromium.org> | 2015-07-13 12:31:07 -0700 |
---|---|---|
committer | Eric Roman <eroman@chromium.org> | 2015-07-13 19:32:01 +0000 |
commit | 2616decc432549bf1cc97566d0df296b4412584e (patch) | |
tree | 59f8cb73aa0ff13bfb1acc16b2c9bb379a30c379 /device | |
parent | c67dc7b06600ad4ea44cfd350847d44866aa4b07 (diff) | |
download | chromium_src-2616decc432549bf1cc97566d0df296b4412584e.zip chromium_src-2616decc432549bf1cc97566d0df296b4412584e.tar.gz chromium_src-2616decc432549bf1cc97566d0df296b4412584e.tar.bz2 |
Add constructors for IOBuffer that take the buffer length as a size_t.
Once the consumers have all been updated to work with unsigned buffer lengths, I will remove the signed int versions. For now this change adds some runtime safety checks, and facilitates the ongoing conversion to size_t.
A minority of consumers were calling IOBuffer with something other than "int" or "size_t", and those were updated by this change.
BUG=488553,491315
TBR=michaeln@chromium.org,pfeldman@chromium.org,bradnelson@chromium.org, rockot@chromium.org, dimich@chromium.org
Review URL: https://codereview.chromium.org/1147333003
Cr-Commit-Position: refs/heads/master@{#331485}
(cherry picked from commit 23ba60b3b6e4e6cfa36684ddf621a6afcc6906e4)
Review URL: https://codereview.chromium.org/1230413004 .
Cr-Commit-Position: refs/branch-heads/2403@{#498}
Cr-Branched-From: f54b8097a9c45ed4ad308133d49f05325d6c5070-refs/heads/master@{#330231}
Diffstat (limited to 'device')
-rw-r--r-- | device/hid/hid_connection_mac.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/device/hid/hid_connection_mac.cc b/device/hid/hid_connection_mac.cc index de93cc6..57f56af 100644 --- a/device/hid/hid_connection_mac.cc +++ b/device/hid/hid_connection_mac.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/location.h" #include "base/mac/foundation_util.h" +#include "base/numerics/safe_math.h" #include "base/single_thread_task_runner.h" #include "base/strings/stringprintf.h" #include "base/thread_task_runner_handle.h" @@ -135,10 +136,12 @@ void HidConnectionMac::InputReportCallback(void* context, scoped_refptr<net::IOBufferWithSize> buffer; if (connection->device_info()->has_report_id()) { // report_id is already contained in report_bytes - buffer = new net::IOBufferWithSize(report_length); + buffer = new net::IOBufferWithSize( + base::CheckedNumeric<size_t>(report_length).ValueOrDie()); memcpy(buffer->data(), report_bytes, report_length); } else { - buffer = new net::IOBufferWithSize(report_length + 1); + buffer = new net::IOBufferWithSize( + (base::CheckedNumeric<size_t>(report_length) + 1).ValueOrDie()); buffer->data()[0] = 0; memcpy(buffer->data() + 1, report_bytes, report_length); } |