From 2d79e18b255cb226b60bf7d0d5c47b7b325e084e Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Fri, 24 Jan 2025 18:20:06 +0800 Subject: [PATCH] fix(strings): fix access out-of-bounds when converting zero-length strings to null-terminated strings --- Redcraft.Utility/Source/Public/Strings/String.h | 5 +---- Redcraft.Utility/Source/Public/Strings/StringView.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Strings/String.h b/Redcraft.Utility/Source/Public/Strings/String.h index 73c47c8..72362f6 100644 --- a/Redcraft.Utility/Source/Public/Strings/String.h +++ b/Redcraft.Utility/Source/Public/Strings/String.h @@ -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(); } diff --git a/Redcraft.Utility/Source/Public/Strings/StringView.h b/Redcraft.Utility/Source/Public/Strings/StringView.h index d58decc..f1ea7c0 100644 --- a/Redcraft.Utility/Source/Public/Strings/StringView.h +++ b/Redcraft.Utility/Source/Public/Strings/StringView.h @@ -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(this->GetData(), false); }