aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs/statusor.h
diff options
context:
space:
mode:
authorGravatar Brian Silverman <brian@peloton-tech.com>2016-01-20 23:05:25 -0500
committerGravatar Brian Silverman <brian@peloton-tech.com>2016-01-20 23:05:25 -0500
commit96c2dd5dfc7359936ca02ac5e18142caeb485a33 (patch)
tree72d98d5ced420c849bb66f518da7d29999a86259 /src/google/protobuf/stubs/statusor.h
parentfe066bd514fcd08f2c2bf94d3d0e89e3c4f10884 (diff)
Avoid upcasting uninitialized pointers
Fixes google/protobuf#693 msan flags this as being undefined behavior. I think it's triggering because the compiler has to insert a branch to avoid changing the pointer's value if it starts out NULL. I can't figure out if this is actually undefined behavior or not, but it definitely seems to be a gray area of the standard which is best avoided.
Diffstat (limited to 'src/google/protobuf/stubs/statusor.h')
-rw-r--r--src/google/protobuf/stubs/statusor.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/google/protobuf/stubs/statusor.h b/src/google/protobuf/stubs/statusor.h
index a9d2b374..ad848701 100644
--- a/src/google/protobuf/stubs/statusor.h
+++ b/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 U>
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 U>
inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<U>& other) {
status_ = other.status_;
- value_ = other.value_;
+ if (status_.ok()) value_ = other.value_;
return *this;
}