Fix some UBSAN warnings.
* external/com_google_protobuf/src/google/protobuf/stubs/strutil.cc:1122:9: runtime error: negation of -9223372036854775808 cannot be represented in type 'google::protobuf::int64' (aka 'long'); cast to an unsigned type to negate this value to itself
* Bad external/com_google_protobuf/src/google/protobuf/text_format.cc:1320:14: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:62:62: note: nonnull attribute specified here
Signed-off-by: Harvey Tuch <htuch@google.com>
diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
index 1d34870..3844fa6 100644
--- a/src/google/protobuf/stubs/strutil.cc
+++ b/src/google/protobuf/stubs/strutil.cc
@@ -1116,10 +1116,12 @@
}
char* FastInt64ToBufferLeft(int64 i, char* buffer) {
- uint64 u = i;
+ uint64 u = 0;
if (i < 0) {
*buffer++ = '-';
- u = -i;
+ u -= i;
+ } else {
+ u = i;
}
return FastUInt64ToBufferLeft(u, buffer);
}
diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc
index ba0c302..801a8e3 100644
--- a/src/google/protobuf/text_format.cc
+++ b/src/google/protobuf/text_format.cc
@@ -1315,7 +1315,9 @@
while (size > buffer_size_) {
// Data exceeds space in the buffer. Write what we can and request a new
// buffer.
- memset(buffer_, ' ', buffer_size_);
+ if (buffer_size_ > 0) {
+ memset(buffer_, ' ', buffer_size_);
+ }
size -= buffer_size_;
void* void_buffer;
failed_ = !output_->Next(&void_buffer, &buffer_size_);