Эх сурвалжийг харах

Merge pull request #1162 from brian-peloton/master

Avoid upcasting uninitialized pointers
Feng Xiao 9 жил өмнө
parent
commit
f2b6dbb8b3

+ 2 - 2
src/google/protobuf/stubs/statusor.h

@@ -224,14 +224,14 @@ inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<T>& other) {
 template<typename T>
 template<typename T>
 template<typename U>
 template<typename U>
 inline StatusOr<T>::StatusOr(const StatusOr<U>& other)
 inline StatusOr<T>::StatusOr(const StatusOr<U>& other)
-    : status_(other.status_), value_(other.value_) {
+    : status_(other.status_), value_(other.status_.ok() ? other.value_ : NULL) {
 }
 }
 
 
 template<typename T>
 template<typename T>
 template<typename U>
 template<typename U>
 inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<U>& other) {
 inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<U>& other) {
   status_ = other.status_;
   status_ = other.status_;
-  value_ = other.value_;
+  if (status_.ok()) value_ = other.value_;
   return *this;
   return *this;
 }
 }