mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-29 14:20:29 +00:00
[libfuzzer] adding std:string to allowed adaptable argument.
llvm-svn: 262757
This commit is contained in:
parent
caaf1ef4e5
commit
a4ce43c759
@ -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.
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user