Skip to content

Commit 54baf6b

Browse files
committed
ICU-20392 Bugfix: Don't access old std::variant<> data after emplace().
This just happens to work a lot of the time but it isn't correct.
1 parent 8c60b93 commit 54baf6b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

icu4c/source/common/locid.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,21 +1994,20 @@ Locale& Locale::init(StringPiece localeID, UBool canonicalize)
19941994
U_ASSERT(fullNameBuffer.isEmpty());
19951995
nest.init(language, script, region, variantBegin);
19961996
} else {
1997-
std::unique_ptr<Heap>& heap = payload.emplace<std::unique_ptr<Heap>>(
1998-
std::make_unique<Heap>(language, script, region, variantBegin));
1999-
if (!heap) {
2000-
break; // error: out of memory
2001-
}
20021997
if (fullName == nest.baseName) {
20031998
U_ASSERT(fullNameBuffer.isEmpty());
2004-
heap->fullName = {fullName, static_cast<std::string_view::size_type>(length)};
2005-
if (heap->fullName.isEmpty()) {
1999+
fullNameBuffer = {fullName, static_cast<std::string_view::size_type>(length)};
2000+
if (fullNameBuffer.isEmpty()) {
20062001
break; // error: out of memory
20072002
}
2008-
} else {
2009-
U_ASSERT(!fullNameBuffer.isEmpty());
2010-
heap->fullName = std::move(fullNameBuffer);
20112003
}
2004+
std::unique_ptr<Heap>& heap = payload.emplace<std::unique_ptr<Heap>>(
2005+
std::make_unique<Heap>(language, script, region, variantBegin));
2006+
if (!heap) {
2007+
break; // error: out of memory
2008+
}
2009+
U_ASSERT(!fullNameBuffer.isEmpty());
2010+
heap->fullName = std::move(fullNameBuffer);
20122011
}
20132012

20142013
initBaseName(err);

0 commit comments

Comments
 (0)