Skip to content

Commit 2c6361e

Browse files
Tamir Dubersteinfacebook-github-bot
authored andcommitted
Avoid use-after-return caused by double move
Summary: Previously, `Result<T>`'s constructor used `std::move(val)` to initialize the value. This resulted in an unnecessary extra move and destructor call on a moved-from stack object, triggering an HWASAN stack tag mismatch when the moved-from object was later destructed. Replacing `std::move(val)` with `std::forward<T>(val)` avoids the extra move while preserving correct semantics. This ensures only one move occurs and avoids lifetime violations that can lead to tag mismatches under HWASAN. Reviewed By: StefanBossbaly Differential Revision: D76271359
1 parent 611092d commit 2c6361e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

runtime/core/result.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ class Result final {
7070
/// Value copy constructor.
7171
/* implicit */ Result(const T& val) : value_(val), hasValue_(true) {}
7272

73-
/// Value move constructor.
74-
/* implicit */ Result(T&& val) : value_(std::move(val)), hasValue_(true) {}
73+
/// Value forwarding constructor.
74+
/* implicit */ Result(T&& val)
75+
: value_(std::forward<T>(val)), hasValue_(true) {}
7576

7677
/// Result move constructor.
7778
/* implicit */ Result(Result&& rhs) noexcept : hasValue_(rhs.hasValue_) {

0 commit comments

Comments
 (0)