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

Side by Side Diff: base/pickle.cc

Issue 2797283002: Fixing std::swap(x, x) in base. (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/pickle.h" 5 #include "base/pickle.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <algorithm> // for max() 9 #include <algorithm> // for max()
10 #include <limits> 10 #include <limits>
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 Resize(other.header_->payload_size); 300 Resize(other.header_->payload_size);
301 memcpy(header_, other.header_, header_size_ + other.header_->payload_size); 301 memcpy(header_, other.header_, header_size_ + other.header_->payload_size);
302 } 302 }
303 303
304 Pickle::~Pickle() { 304 Pickle::~Pickle() {
305 if (capacity_after_header_ != kCapacityReadOnly) 305 if (capacity_after_header_ != kCapacityReadOnly)
306 free(header_); 306 free(header_);
307 } 307 }
308 308
309 Pickle& Pickle::operator=(const Pickle& other) { 309 Pickle& Pickle::operator=(const Pickle& other) {
310 if (this == &other) {
311 NOTREACHED();
dcheng 2017/04/05 20:22:18 The post condition for CopyAssignment in N4618 [1]
dyaroshev 2017/04/05 20:42:47 This NOTREACHED mislead me - I read it as move ass
dcheng 2017/04/05 20:45:49 Dropping the NOTREACHED() seems fine, as long as k
dyaroshev 2017/04/05 20:54:17 Done.
312 return *this;
313 }
314 if (capacity_after_header_ == kCapacityReadOnly) { 310 if (capacity_after_header_ == kCapacityReadOnly) {
315 header_ = NULL; 311 header_ = NULL;
316 capacity_after_header_ = 0; 312 capacity_after_header_ = 0;
317 } 313 }
318 if (header_size_ != other.header_size_) { 314 if (header_size_ != other.header_size_) {
319 free(header_); 315 free(header_);
320 header_ = NULL; 316 header_ = NULL;
321 header_size_ = other.header_size_; 317 header_size_ = other.header_size_;
322 } 318 }
323 Resize(other.header_->payload_size); 319 Resize(other.header_->payload_size);
324 memcpy(header_, other.header_, 320 memcpy(header_, other.header_,
danakj 2017/04/05 19:17:40 memcpy of overlapping memory is not allowed
dyaroshev 2017/04/05 20:42:47 I reverted this file.
325 other.header_size_ + other.header_->payload_size); 321 other.header_size_ + other.header_->payload_size);
326 write_offset_ = other.write_offset_; 322 write_offset_ = other.write_offset_;
327 return *this; 323 return *this;
328 } 324 }
329 325
330 bool Pickle::WriteString(const StringPiece& value) { 326 bool Pickle::WriteString(const StringPiece& value) {
331 if (!WriteInt(static_cast<int>(value.size()))) 327 if (!WriteInt(static_cast<int>(value.size())))
332 return false; 328 return false;
333 329
334 return WriteBytes(value.data(), static_cast<int>(value.size())); 330 return WriteBytes(value.data(), static_cast<int>(value.size()));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 469
474 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { 470 inline void Pickle::WriteBytesCommon(const void* data, size_t length) {
475 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) 471 DCHECK_NE(kCapacityReadOnly, capacity_after_header_)
476 << "oops: pickle is readonly"; 472 << "oops: pickle is readonly";
477 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); 473 MSAN_CHECK_MEM_IS_INITIALIZED(data, length);
478 void* write = ClaimUninitializedBytesInternal(length); 474 void* write = ClaimUninitializedBytesInternal(length);
479 memcpy(write, data, length); 475 memcpy(write, data, length);
480 } 476 }
481 477
482 } // namespace base 478 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698