Skip to content

Commit

Permalink
Fix error in Clang UndefinedBehaviorSanitizer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PetterS committed May 4, 2018
1 parent 513b35d commit d14cacd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/google/protobuf/io/printer.cc
Expand Up @@ -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;
Expand Down

0 comments on commit d14cacd

Please sign in to comment.