SmallString: Improve self-assignment behaviour

This commit is contained in:
chaoticgd
2026-03-15 23:39:55 +00:00
committed by Ty
parent 6aed46c603
commit d049c395fc
3 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -392,7 +392,8 @@ void SmallStringBase::vsprintf(const char* format, va_list ap)
void SmallStringBase::assign(const SmallStringBase& copy)
{
assign(copy.c_str(), copy.length());
if (this != &copy)
assign(copy.c_str(), copy.length());
}
void SmallStringBase::assign(const char* str)
+1
View File
@@ -2,6 +2,7 @@ add_pcsx2_test(common_test
byteswap_tests.cpp
filesystem_tests.cpp
path_tests.cpp
small_string_tests.cpp
string_util_tests.cpp
)
+12
View File
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
#include "common/SmallString.h"
#include <gtest/gtest.h>
TEST(StackString, SelfAssignment)
{
SmallStackString<6> string("Hello");
string = string;
ASSERT_STREQ(string.c_str(), "Hello");
}