fix(strings): fix access out-of-bounds when converting zero-length strings to null-terminated strings

This commit is contained in:
Redstone1024 2025-01-24 18:20:06 +08:00
parent 1d5a61f308
commit 2d79e18b25
2 changed files with 2 additions and 5 deletions

View File

@ -1124,10 +1124,7 @@ public:
/** @return The non-modifiable standard C character string version of the string. */
NODISCARD FORCEINLINE auto operator*() &&
{
if (this->Back() != LITERAL(T, '\0'))
{
this->PushBack(LITERAL(T, '\0'));
}
if (!EndsWith(LITERAL(T, '\0'))) this->PushBack(LITERAL(T, '\0'));
return AsConst(*this).GetData();
}

View File

@ -493,7 +493,7 @@ public:
/** @return The non-modifiable standard C character string version of the string view. */
NODISCARD FORCEINLINE auto operator*() const
{
if (this->Back() == LITERAL(FElementType, '\0') || Contains(LITERAL(FElementType, '\0')))
if (EndsWith(LITERAL(FElementType, '\0')) || Contains(LITERAL(FElementType, '\0')))
{
return NAMESPACE_PRIVATE::TCStringFromTStringView<FElementType>(this->GetData(), false);
}