[libfuzzer] adding std:string to allowed adaptable argument.

llvm-svn: 262757
This commit is contained in:
Mike Aizatsky 2016-03-04 23:18:01 +00:00
parent caaf1ef4e5
commit a4ce43c759
2 changed files with 20 additions and 0 deletions

View File

@ -92,6 +92,17 @@ size_t UnpackSingle<std::vector<uint8_t>>(const uint8_t *Data, size_t Size,
return Size - Len - 1;
}
template <>
size_t UnpackSingle<std::string>(const uint8_t *Data, size_t Size,
std::string *Value) {
if (Size < 1)
return Size;
size_t Len = std::min(static_cast<size_t>(*Data), Size - 1);
std::string S(Data + 1, Data + 1 + Len);
Value->swap(S);
return Size - Len - 1;
}
// Unpacking into arbitrary tuple.
// Recursion guard.

View File

@ -70,6 +70,15 @@ TEST(Unpack, Vector) {
EXPECT_EQ(8, V[1]);
}
TEST(Unpack, String) {
std::tuple<std::string> T;
const auto &S = std::get<0>(T);
EXPECT_TRUE(Unpack(&T, {2, 3}));
EXPECT_EQ(1ul, S.size());
EXPECT_EQ(3, S[0]);
}
template <typename Fn>
bool UnpackAndApply(Fn F, std::initializer_list<uint8_t> Data) {
std::vector<uint8_t> V(Data);