diff options
author | Petter Strandmark <petter.strandmark@gmail.com> | 2018-05-04 20:37:03 +0200 |
---|---|---|
committer | Petter Strandmark <petter.strandmark@gmail.com> | 2018-05-04 20:37:03 +0200 |
commit | d14cacd791ac553b5dfba5f303fc631b42f6e662 (patch) | |
tree | 548d536d70eab290b05f712613710ab79b1129a5 /src/google/protobuf/io/printer.cc | |
parent | 513b35dc4e732a5649d50b2c56405109def40624 (diff) | |
download | protobuf-d14cacd791ac553b5dfba5f303fc631b42f6e662.tar.gz protobuf-d14cacd791ac553b5dfba5f303fc631b42f6e662.tar.bz2 protobuf-d14cacd791ac553b5dfba5f303fc631b42f6e662.zip |
Fix error in Clang UndefinedBehaviorSanitizer
Pointer Arguments to memcpy can not be null in UndefinedBehaviorSanitizer.
In this case, both the memory and the size was zero. This change allows
protoc to run under UndefinedBehaviorSanitizer.
Diffstat (limited to 'src/google/protobuf/io/printer.cc')
-rw-r--r-- | src/google/protobuf/io/printer.cc | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index 8493268d..de67cef1 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -350,10 +350,12 @@ void Printer::CopyToBuffer(const char* data, int size) { while (size > buffer_size_) { // Data exceeds space in the buffer. Copy what we can and request a // new buffer. - memcpy(buffer_, data, buffer_size_); - offset_ += buffer_size_; - data += buffer_size_; - size -= buffer_size_; + if (buffer_size_ > 0) { + memcpy(buffer_, data, buffer_size_); + offset_ += buffer_size_; + data += buffer_size_; + size -= buffer_size_; + } void* void_buffer; failed_ = !output_->Next(&void_buffer, &buffer_size_); if (failed_) return; |