Fix MSAN issue in #1626 This patch fixes an MSAN issue by changing CZString initialization.
diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a875d28..640c7a2 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp
@@ -253,20 +253,29 @@ cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ != nullptr ? duplicateStringValue(other.cstr_, other.storage_.length_) : other.cstr_); - storage_.policy_ = - static_cast<unsigned>( - other.cstr_ - ? (static_cast<DuplicationPolicy>(other.storage_.policy_) == - noDuplication - ? noDuplication - : duplicate) - : static_cast<DuplicationPolicy>(other.storage_.policy_)) & - 3U; - storage_.length_ = other.storage_.length_; + if (other.cstr_) { + storage_.policy_ = + static_cast<unsigned>( + other.cstr_ + ? (static_cast<DuplicationPolicy>(other.storage_.policy_) == + noDuplication + ? noDuplication + : duplicate) + : static_cast<DuplicationPolicy>(other.storage_.policy_)) & + 3U; + storage_.length_ = other.storage_.length_; + } else { + index_ = other.index_; + } } -Value::CZString::CZString(CZString&& other) noexcept - : cstr_(other.cstr_), index_(other.index_) { +Value::CZString::CZString(CZString&& other) noexcept : cstr_(other.cstr_) { + if (other.cstr_) { + storage_.policy_ = other.storage_.policy_; + storage_.length_ = other.storage_.length_; + } else { + index_ = other.index_; + } other.cstr_ = nullptr; } @@ -293,7 +302,12 @@ Value::CZString& Value::CZString::operator=(CZString&& other) noexcept { cstr_ = other.cstr_; - index_ = other.index_; + if (other.cstr_) { + storage_.policy_ = other.storage_.policy_; + storage_.length_ = other.storage_.length_; + } else { + index_ = other.index_; + } other.cstr_ = nullptr; return *this; }