From e6ac2a292fac59032eb3ba11847a43bd5837c30c Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 25 Apr 2024 15:06:38 -0700 Subject: [PATCH] ICU-22753 Fix read-after-move in MF2 In StaticErrors::addError() and DynamicErrors::addError(), don't read from `e` after moving out of it. --- icu4c/source/i18n/messageformat2_errors.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/icu4c/source/i18n/messageformat2_errors.cpp b/icu4c/source/i18n/messageformat2_errors.cpp index 48fa17a79ad..cbb9e1497d6 100644 --- a/icu4c/source/i18n/messageformat2_errors.cpp +++ b/icu4c/source/i18n/messageformat2_errors.cpp @@ -189,10 +189,12 @@ namespace message2 { void StaticErrors::addError(StaticError&& e, UErrorCode& status) { CHECK_ERROR(status); + StaticErrorType type = e.type; + void* errorP = static_cast(create(std::move(e), status)); U_ASSERT(syntaxAndDataModelErrors.isValid()); - switch (e.type) { + switch (type) { case StaticErrorType::SyntaxError: { syntaxError = true; break; @@ -229,10 +231,12 @@ namespace message2 { void DynamicErrors::addError(DynamicError&& e, UErrorCode& status) { CHECK_ERROR(status); + DynamicErrorType type = e.type; + void* errorP = static_cast(create(std::move(e), status)); U_ASSERT(resolutionAndFormattingErrors.isValid()); - switch (e.type) { + switch (type) { case DynamicErrorType::UnresolvedVariable: { unresolvedVariableError = true; resolutionAndFormattingErrors->adoptElement(errorP, status);