diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/StringExtras.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/StringExtras.cpp index 0b9f7d42f0..930772488e 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/StringExtras.cpp +++ b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/StringExtras.cpp @@ -362,7 +362,7 @@ std::optional wpi::parse_float( std::pair wpi::UnescapeCString( std::string_view str, wpi::SmallVectorImpl& buf) { buf.clear(); - buf.reserve(str.size() - 2); + buf.reserve(str.size()); const char* s = str.data(); const char* end = str.data() + str.size(); for (; s != end && *s != '"'; ++s) { diff --git a/wpiutil/src/test/native/cpp/UnescapeCStringTest.cpp b/wpiutil/src/test/native/cpp/UnescapeCStringTest.cpp index d3aa63c34b..7f0ca5fcf8 100644 --- a/wpiutil/src/test/native/cpp/UnescapeCStringTest.cpp +++ b/wpiutil/src/test/native/cpp/UnescapeCStringTest.cpp @@ -52,4 +52,23 @@ TEST(UnescapeCStringTest, Octal) { EXPECT_TRUE(rem.empty()); } +TEST(UnescapeCStringTest, EmptyString) { + SmallString<64> buf; + auto [out, rem] = UnescapeCString("", buf); + EXPECT_EQ(out, ""); +} + +TEST(UnescapeCStringTest, ShortString) { + SmallString<64> buf; + auto [out, rem] = UnescapeCString("a", buf); + EXPECT_EQ(out, "a"); +} + +TEST(UnescapeCStringTest, NoEscapesString) { + SmallString<64> buf; + std::string_view input = "abcdefghijklmnopqrstuvwxyz1234567890"; + auto [out, rem] = UnescapeCString(input, buf); + EXPECT_EQ(out, input); +} + } // namespace