Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2109)

Unified Diff: base/values.cc

Issue 10389088: BinaryValue does not support NULL buffer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Explicit out-of-line destructor. Take 2. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index d561d68377fa1f8c6d2e4d1fa2f6a3eee9413c9f..648d0bc436d7a5679d6dc9374480e8c6e0fe9894 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -298,33 +298,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.release()),
+ 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 {
@@ -333,14 +332,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 ////////////////////
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698