From 836061bde615432d5dfcce8c26a23f217bfdbd29 Mon Sep 17 00:00:00 2001 From: "deanm@google.com" Date: Wed, 13 Aug 2008 14:57:51 +0000 Subject: Don't cast negative values to unsigned. This eliminates warnings in GCC. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@799 0039d316-1c4b-4281-b951-d872f2087c98 --- base/pickle.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'base/pickle.cc') diff --git a/base/pickle.cc b/base/pickle.cc index 356d5df..3c3c7e2 100644 --- a/base/pickle.cc +++ b/base/pickle.cc @@ -39,6 +39,9 @@ // static const int Pickle::kPayloadUnit = 64; +// We mark a read only pickle with a special capacity_. +static const size_t kCapacityReadOnly = std::numeric_limits::max(); + // Payload is uint32 aligned. Pickle::Pickle() @@ -64,7 +67,7 @@ Pickle::Pickle(int header_size) Pickle::Pickle(const char* data, int data_len) : header_(reinterpret_cast(const_cast(data))), header_size_(data_len - header_->payload_size), - capacity_(-1), + capacity_(kCapacityReadOnly), variable_buffer_offset_(0) { DCHECK(header_size_ >= sizeof(Header)); DCHECK(header_size_ == AlignInt(header_size_, sizeof(uint32))); @@ -82,12 +85,12 @@ Pickle::Pickle(const Pickle& other) } Pickle::~Pickle() { - if (capacity_ != -1) + if (capacity_ != kCapacityReadOnly) free(header_); } Pickle& Pickle::operator=(const Pickle& other) { - if (header_size_ != other.header_size_ && capacity_ != -1) { + if (header_size_ != other.header_size_ && capacity_ != kCapacityReadOnly) { free(header_); header_ = NULL; header_size_ = other.header_size_; @@ -258,7 +261,7 @@ void Pickle::EndWrite(char* dest, int length) { } bool Pickle::WriteBytes(const void* data, int data_len) { - DCHECK(capacity_ != -1) << "oops: pickle is readonly"; + DCHECK(capacity_ != kCapacityReadOnly) << "oops: pickle is readonly"; char* dest = BeginWrite(data_len); if (!dest) -- cgit v1.1