summaryrefslogtreecommitdiffstats
path: root/base/values.cc
diff options
context:
space:
mode:
authorrpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-08 03:16:22 +0000
committerrpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-08 03:16:22 +0000
commit2d6504b7c1dec56a67869965ae753c58c154ca91 (patch)
treeddec8ba5ee5afeebaf6306a8e7a0aa28eefcda6e /base/values.cc
parentf4d884436d740ef9eec7b5a6e9b027f5b2ce9d37 (diff)
downloadchromium_src-2d6504b7c1dec56a67869965ae753c58c154ca91.zip
chromium_src-2d6504b7c1dec56a67869965ae753c58c154ca91.tar.gz
chromium_src-2d6504b7c1dec56a67869965ae753c58c154ca91.tar.bz2
BinaryValue support for NULL buffer.
* Apply original change from CL 10389088 (https://chromiumcodereview.appspot.com/10389088) * Change BinaryValue to use "scoped_ptr<char[]>" instead of "scoped_ptr<char>". By contract, the memory owned should be deleted with the "delete[]" operator. BUG=127630 Review URL: https://chromiumcodereview.appspot.com/11745016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.cc')
-rw-r--r--base/values.cc36
1 files changed, 14 insertions, 22 deletions
diff --git a/base/values.cc b/base/values.cc
index 459d56f..7a21709 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -306,33 +306,32 @@ bool StringValue::Equals(const Value* other) const {
///////////////////// BinaryValue ////////////////////
-BinaryValue::~BinaryValue() {
- DCHECK(buffer_);
- if (buffer_)
- delete[] buffer_;
+BinaryValue::BinaryValue()
+ : Value(TYPE_BINARY),
+ buffer_(NULL),
+ size_(0) {
}
-// static
-BinaryValue* BinaryValue::Create(char* buffer, size_t size) {
- if (!buffer)
- return NULL;
+BinaryValue::BinaryValue(scoped_ptr<char[]> buffer, size_t size)
+ : Value(TYPE_BINARY),
+ buffer_(buffer.Pass()),
+ size_(size) {
+}
- return new BinaryValue(buffer, size);
+BinaryValue::~BinaryValue() {
}
// static
BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer,
size_t size) {
- if (!buffer)
- return NULL;
-
char* buffer_copy = new char[size];
memcpy(buffer_copy, buffer, size);
- return new BinaryValue(buffer_copy, size);
+ scoped_ptr<char[]> scoped_buffer_copy(buffer_copy);
+ return new BinaryValue(scoped_buffer_copy.Pass(), size);
}
BinaryValue* BinaryValue::DeepCopy() const {
- return CreateWithCopiedBuffer(buffer_, size_);
+ return CreateWithCopiedBuffer(buffer_.get(), size_);
}
bool BinaryValue::Equals(const Value* other) const {
@@ -341,14 +340,7 @@ bool BinaryValue::Equals(const Value* other) const {
const BinaryValue* other_binary = static_cast<const BinaryValue*>(other);
if (other_binary->size_ != size_)
return false;
- return !memcmp(buffer_, other_binary->buffer_, size_);
-}
-
-BinaryValue::BinaryValue(char* buffer, size_t size)
- : Value(TYPE_BINARY),
- buffer_(buffer),
- size_(size) {
- DCHECK(buffer_);
+ return !memcmp(GetBuffer(), other_binary->GetBuffer(), size_);
}
///////////////////// DictionaryValue ////////////////////