diff options
author | Kostya Serebryany <kcc@google.com> | 2015-12-04 22:29:39 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-12-04 22:29:39 +0000 |
commit | 9e48cda9bc15eef44ee72f4464edf1bbe5aa7267 (patch) | |
tree | 7e3f74d1798ad4423cfdcb20bfb777a7e7fd7a90 /llvm/lib/Fuzzer/FuzzerUtil.cpp | |
parent | 2f107ce1325cda843a548b15a5cad2dfe3162766 (diff) | |
download | bcm5719-llvm-9e48cda9bc15eef44ee72f4464edf1bbe5aa7267.tar.gz bcm5719-llvm-9e48cda9bc15eef44ee72f4464edf1bbe5aa7267.zip |
[libFuzzer] compute base64 in-process instead of using an external lib. Since libFuzzer should not depend on anything, just re-implement base64 encoder. PR25746
llvm-svn: 254784
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerUtil.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerUtil.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerUtil.cpp b/llvm/lib/Fuzzer/FuzzerUtil.cpp index 20a41e0d4fb..6c1133fffd3 100644 --- a/llvm/lib/Fuzzer/FuzzerUtil.cpp +++ b/llvm/lib/Fuzzer/FuzzerUtil.cpp @@ -167,4 +167,33 @@ bool ParseDictionaryFile(const std::string &Text, std::vector<Unit> *Units) { int GetPid() { return getpid(); } + +std::string Base64(const Unit &U) { + static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + std::string Res; + size_t i; + for (i = 0; i + 2 < U.size(); i += 3) { + uint32_t x = (U[i] << 16) + (U[i + 1] << 8) + U[i + 2]; + Res += Table[(x >> 18) & 63]; + Res += Table[(x >> 12) & 63]; + Res += Table[(x >> 6) & 63]; + Res += Table[x & 63]; + } + if (i + 1 == U.size()) { + uint32_t x = (U[i] << 16); + Res += Table[(x >> 18) & 63]; + Res += Table[(x >> 12) & 63]; + Res += "=="; + } else if (i + 2 == U.size()) { + uint32_t x = (U[i] << 16) + (U[i + 1] << 8); + Res += Table[(x >> 18) & 63]; + Res += Table[(x >> 12) & 63]; + Res += Table[(x >> 6) & 63]; + Res += "="; + } + return Res; +} + } // namespace fuzzer |