소스 검색

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.
Petter Strandmark 7 년 전
부모
커밋
d14cacd791
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 4
      src/google/protobuf/io/printer.cc

+ 6 - 4
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;