From 97f6b39503db4204557ecc334d24be723c11dca3 Mon Sep 17 00:00:00 2001 From: Chiraffollo Date: Sat, 27 Jan 2024 00:57:28 +0100 Subject: [PATCH] Fix #832: Only copy/move storage value when optional is valid --- include/etl/optional.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/etl/optional.h b/include/etl/optional.h index d85763d25..6431efb58 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -768,7 +768,10 @@ namespace etl { if (this != &other) { - storage.value = other.storage.value; + if (other.valid) + { + storage.value = other.storage.value; + } valid = other.valid; } @@ -783,7 +786,10 @@ namespace etl { if (this != &other) { - storage.value = etl::move(other.storage.value); + if (other.valid) + { + storage.value = etl::move(other.storage.value); + } valid = other.valid; }