diff options
author | Kostya Serebryany <kcc@google.com> | 2016-01-12 02:36:59 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-01-12 02:36:59 +0000 |
commit | 4174005622e804e0b6f0f3ac7bcc5154b18c29b4 (patch) | |
tree | ced2a8d97e25f7bc753df3b4f184e8ff2358a43c /llvm/lib/Fuzzer/FuzzerUtil.cpp | |
parent | 859e86d9624f1d2fd6c7d45f3c8060cbce5c359b (diff) | |
download | bcm5719-llvm-4174005622e804e0b6f0f3ac7bcc5154b18c29b4.tar.gz bcm5719-llvm-4174005622e804e0b6f0f3ac7bcc5154b18c29b4.zip |
[libFuzzer] when a new unit is discovered using a dictionary, print all used dictionary entries
llvm-svn: 257435
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerUtil.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerUtil.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerUtil.cpp b/llvm/lib/Fuzzer/FuzzerUtil.cpp index 6c1133fffd3..d7226cfce96 100644 --- a/llvm/lib/Fuzzer/FuzzerUtil.cpp +++ b/llvm/lib/Fuzzer/FuzzerUtil.cpp @@ -27,13 +27,26 @@ void Print(const Unit &v, const char *PrintAfter) { Printf("%s", PrintAfter); } +void PrintASCIIByte(uint8_t Byte) { + if (Byte == '\\') + Printf("\\\\"); + else if (Byte == '"') + Printf("\\\""); + else if (Byte >= 32 && Byte < 127) + Printf("%c", Byte); + else + Printf("\\x%02x", Byte); +} + +void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter) { + for (size_t i = 0; i < Size; i++) + PrintASCIIByte(Data[i]); + Printf("%s", PrintAfter); +} + void PrintASCII(const Unit &U, const char *PrintAfter) { - for (auto X : U) { - if (isprint(X)) - Printf("%c", X); - else - Printf("\\x%x", (unsigned)X); - } + for (auto X : U) + PrintASCIIByte(X); Printf("%s", PrintAfter); } |