Skip to content

Commit

Permalink
ICU-22753 Fix read-after-move in MF2
Browse files Browse the repository at this point in the history
In StaticErrors::addError() and DynamicErrors::addError(),
don't read from `e` after moving out of it.
  • Loading branch information
catamorphism authored and echeran committed May 14, 2024
1 parent 084af5c commit e6ac2a2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions icu4c/source/i18n/messageformat2_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ namespace message2 {
void StaticErrors::addError(StaticError&& e, UErrorCode& status) {
CHECK_ERROR(status);

StaticErrorType type = e.type;

void* errorP = static_cast<void*>(create<StaticError>(std::move(e), status));
U_ASSERT(syntaxAndDataModelErrors.isValid());

switch (e.type) {
switch (type) {
case StaticErrorType::SyntaxError: {
syntaxError = true;
break;
Expand Down Expand Up @@ -229,10 +231,12 @@ namespace message2 {
void DynamicErrors::addError(DynamicError&& e, UErrorCode& status) {
CHECK_ERROR(status);

DynamicErrorType type = e.type;

void* errorP = static_cast<void*>(create<DynamicError>(std::move(e), status));
U_ASSERT(resolutionAndFormattingErrors.isValid());

switch (e.type) {
switch (type) {
case DynamicErrorType::UnresolvedVariable: {
unresolvedVariableError = true;
resolutionAndFormattingErrors->adoptElement(errorP, status);
Expand Down

0 comments on commit e6ac2a2

Please sign in to comment.