From f2d7fc149f1ba0d8f7299b7070551a0651f1d744 Mon Sep 17 00:00:00 2001 From: "gears.daemon" Date: Sun, 10 Feb 2008 11:00:24 +0000 Subject: [PATCH] [Author: aa] Cloned from CL 6417434 by 'g4 patch'. Original change by kevinww@kevinww-gears-ie-test on 2008/02/10 01:32:44. Fix build breakage on Windows in BufferBlob (addressing vector with an int64) PRESUBMIT=passed TBR=kevinww OCL=6417471 SCL=6417475 git-svn-id: https://google-gears.googlecode.com/svn/trunk@884 fe895e04-df30-0410-9975-d76d301b4276 --- gears/blob/buffer_blob.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gears/blob/buffer_blob.cc b/gears/blob/buffer_blob.cc index 6201182..44fd11e 100644 --- a/gears/blob/buffer_blob.cc +++ b/gears/blob/buffer_blob.cc @@ -31,7 +31,8 @@ int BufferBlob::Append(const void *source, int num_bytes) { MutexLock lock(&mutex_); if (!writable_ || num_bytes < 0 || - buffer_.size() + num_bytes < 0) { // Overflow + // Don't try to support BufferBlobs over 2GB: + static_cast(buffer_.size()) + num_bytes > kint32max) { return 0; } int original_size = buffer_.size(); @@ -56,16 +57,18 @@ int BufferBlob::Read(uint8 *destination, int max_bytes, int64 position) const { // By this point, we've established that the blob will not change so we // don't need the mutex lock any more. } + assert(position <= kint32max); // Enforced by Append() if (position >= buffer_.size() || position < 0 || max_bytes < 0) { return 0; } - int actual = buffer_.size() - static_cast(position); + int position_as_int = static_cast(position); + int actual = buffer_.size() - position_as_int; if (actual > max_bytes) { actual = max_bytes; } - memcpy(destination, &(buffer_[position]), actual); + memcpy(destination, &(buffer_[position_as_int]), actual); return actual; } -- 2.11.4.GIT