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

Side by Side 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: 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 unified diff | Download patch
« base/values.h ('K') | « base/values.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/values.h" 5 #include "base/values.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/float_util.h" 9 #include "base/float_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 bool StringValue::Equals(const Value* other) const { 292 bool StringValue::Equals(const Value* other) const {
293 if (other->GetType() != GetType()) 293 if (other->GetType() != GetType())
294 return false; 294 return false;
295 std::string lhs, rhs; 295 std::string lhs, rhs;
296 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; 296 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs;
297 } 297 }
298 298
299 ///////////////////// BinaryValue //////////////////// 299 ///////////////////// BinaryValue ////////////////////
300 300
301 BinaryValue::~BinaryValue() { 301 BinaryValue::~BinaryValue() {
302 DCHECK(buffer_);
303 if (buffer_) 302 if (buffer_)
304 delete[] buffer_; 303 delete[] buffer_;
305 } 304 }
306 305
307 // static 306 // static
308 BinaryValue* BinaryValue::Create(char* buffer, size_t size) { 307 BinaryValue* BinaryValue::Create(char* buffer, size_t size) {
309 if (!buffer)
310 return NULL;
311
312 return new BinaryValue(buffer, size); 308 return new BinaryValue(buffer, size);
313 } 309 }
314 310
315 // static 311 // static
316 BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, 312 BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer,
317 size_t size) { 313 size_t size) {
318 if (!buffer)
319 return NULL;
320
321 char* buffer_copy = new char[size]; 314 char* buffer_copy = new char[size];
322 memcpy(buffer_copy, buffer, size); 315 memcpy(buffer_copy, buffer, size);
323 return new BinaryValue(buffer_copy, size); 316 return new BinaryValue(buffer_copy, size);
324 } 317 }
325 318
326 BinaryValue* BinaryValue::DeepCopy() const { 319 BinaryValue* BinaryValue::DeepCopy() const {
327 return CreateWithCopiedBuffer(buffer_, size_); 320 return CreateWithCopiedBuffer(buffer_, size_);
328 } 321 }
329 322
330 bool BinaryValue::Equals(const Value* other) const { 323 bool BinaryValue::Equals(const Value* other) const {
331 if (other->GetType() != GetType()) 324 if (other->GetType() != GetType())
332 return false; 325 return false;
333 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); 326 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other);
334 if (other_binary->size_ != size_) 327 if (other_binary->size_ != size_)
335 return false; 328 return false;
336 return !memcmp(buffer_, other_binary->buffer_, size_); 329 return !memcmp(buffer_, other_binary->buffer_, size_);
337 } 330 }
338 331
339 BinaryValue::BinaryValue(char* buffer, size_t size) 332 BinaryValue::BinaryValue(char* buffer, size_t size)
340 : Value(TYPE_BINARY), 333 : Value(TYPE_BINARY),
341 buffer_(buffer), 334 buffer_(buffer),
342 size_(size) { 335 size_(size) {
343 DCHECK(buffer_);
344 } 336 }
345 337
346 ///////////////////// DictionaryValue //////////////////// 338 ///////////////////// DictionaryValue ////////////////////
347 339
348 DictionaryValue::DictionaryValue() 340 DictionaryValue::DictionaryValue()
349 : Value(TYPE_DICTIONARY) { 341 : Value(TYPE_DICTIONARY) {
350 } 342 }
351 343
352 DictionaryValue::~DictionaryValue() { 344 DictionaryValue::~DictionaryValue() {
353 Clear(); 345 Clear();
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 if (lhs_it != end() || rhs_it != other_list->end()) 937 if (lhs_it != end() || rhs_it != other_list->end())
946 return false; 938 return false;
947 939
948 return true; 940 return true;
949 } 941 }
950 942
951 ValueSerializer::~ValueSerializer() { 943 ValueSerializer::~ValueSerializer() {
952 } 944 }
953 945
954 } // namespace base 946 } // namespace base
OLDNEW
« base/values.h ('K') | « base/values.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698