summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authordavidben <davidben@chromium.org>2015-11-11 19:37:50 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-12 03:38:42 +0000
commit77ae92f76592329b778f8c25fced54345e0c8d58 (patch)
tree7583cf67702a2940a154cdc01ac202df857eca6e /content
parentfb22f5de3fe0bc038e38ce64573442bb41cfe21a (diff)
downloadchromium_src-77ae92f76592329b778f8c25fced54345e0c8d58.zip
chromium_src-77ae92f76592329b778f8c25fced54345e0c8d58.tar.gz
chromium_src-77ae92f76592329b778f8c25fced54345e0c8d58.tar.bz2
Use size_t for ViewHttpCacheJob::data_offset_.
Noticed this in a code review I was doing and it bugged me. The //net interface it talks to is still problematic, but fixing the offset into the std::string is easy. BUG=491315 Review URL: https://codereview.chromium.org/1433933004 Cr-Commit-Position: refs/heads/master@{#359245}
Diffstat (limited to 'content')
-rw-r--r--content/browser/net/view_http_cache_job_factory.cc23
1 files changed, 16 insertions, 7 deletions
diff --git a/content/browser/net/view_http_cache_job_factory.cc b/content/browser/net/view_http_cache_job_factory.cc
index 41e7b377..823ced9 100644
--- a/content/browser/net/view_http_cache_job_factory.cc
+++ b/content/browser/net/view_http_cache_job_factory.cc
@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
+#include "base/numerics/safe_conversions.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h"
@@ -44,8 +45,15 @@ class ViewHttpCacheJob : public net::URLRequestJob {
bool GetCharset(std::string* charset) override {
return core_->GetCharset(charset);
}
- bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override {
- return core_->ReadRawData(buf, buf_size, bytes_read);
+ bool ReadRawData(net::IOBuffer* buf,
+ int buf_size,
+ int* out_bytes_read) override {
+ size_t bytes_read;
+ if (!core_->ReadRawData(buf, base::checked_cast<size_t>(buf_size),
+ &bytes_read))
+ return false;
+ *out_bytes_read = base::checked_cast<int>(bytes_read);
+ return true;
}
private:
@@ -65,7 +73,7 @@ class ViewHttpCacheJob : public net::URLRequestJob {
bool GetMimeType(std::string* mime_type) const;
bool GetCharset(std::string* charset);
- bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
+ bool ReadRawData(net::IOBuffer* buf, size_t buf_size, size_t* bytes_read);
private:
friend class base::RefCounted<Core>;
@@ -76,7 +84,7 @@ class ViewHttpCacheJob : public net::URLRequestJob {
void OnIOComplete(int result);
std::string data_;
- int data_offset_;
+ size_t data_offset_;
net::ViewCacheHelper cache_helper_;
net::CompletionCallback callback_;
base::Closure user_callback_;
@@ -165,10 +173,11 @@ bool ViewHttpCacheJob::Core::GetCharset(std::string* charset) {
}
bool ViewHttpCacheJob::Core::ReadRawData(net::IOBuffer* buf,
- int buf_size,
- int* bytes_read) {
+ size_t buf_size,
+ size_t* bytes_read) {
DCHECK(bytes_read);
- int remaining = static_cast<int>(data_.size()) - data_offset_;
+ DCHECK_LE(data_offset_, data_.size());
+ size_t remaining = data_.size() - data_offset_;
if (buf_size > remaining)
buf_size = remaining;
memcpy(buf->data(), data_.data() + data_offset_, buf_size);