[wpiutil] Fix UnescapeCString overflow when inputSize < 2 (#4796)

Add tests for empty, small, and string without escapes.
This commit is contained in:
Ryan Blue
2022-12-11 10:36:38 -05:00
committed by GitHub
parent 4a0ad6b48c
commit a31459bce6
2 changed files with 20 additions and 1 deletions

View File

@@ -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