diff --git a/libafl_cc/src/autotokens-pass.cc b/libafl_cc/src/autotokens-pass.cc index b42ab47762..170cd2750d 100644 --- a/libafl_cc/src/autotokens-pass.cc +++ b/libafl_cc/src/autotokens-pass.cc @@ -619,40 +619,45 @@ bool AutoTokensPass::runOnModule(Module &M) { LLVMContext &Ctx = M.getContext(); - size_t memlen = 0, count = 0, offset = 0; + if (dictionary.size()) { + size_t memlen = 0, count = 0, offset = 0; - // sort and unique the dictionary - std::sort(dictionary.begin(), dictionary.end()); - auto last = std::unique(dictionary.begin(), dictionary.end()); - dictionary.erase(last, dictionary.end()); + // sort and unique the dictionary + std::sort(dictionary.begin(), dictionary.end()); + auto last = std::unique(dictionary.begin(), dictionary.end()); + dictionary.erase(last, dictionary.end()); - for (auto token : dictionary) { - memlen += token.length(); - count++; - } - - auto ptrhld = std::unique_ptr(new char[memlen + count]); - - count = 0; - - for (auto token : dictionary) { - if (offset + token.length() < 0xfffff0 && count < MAX_AUTO_EXTRAS) { - // This lenght is guranteed to be < MAX_AUTO_EXTRA - ptrhld.get()[offset++] = (uint8_t)token.length(); - memcpy(ptrhld.get() + offset, token.c_str(), token.length()); - offset += token.length(); + for (auto token : dictionary) { + memlen += token.length(); count++; } - } - // Type - ArrayType *arrayTy = ArrayType::get(IntegerType::get(Ctx, 8), offset); - // The actual dict - GlobalVariable *dict = new GlobalVariable( - M, arrayTy, true, GlobalVariable::ExternalLinkage, - ConstantDataArray::get(Ctx, *(new ArrayRef(ptrhld.get(), offset))), - "libafl_dictionary_" + M.getName()); - dict->setSection("libafl_token"); + if (count) { + auto ptrhld = std::unique_ptr(new char[memlen + count]); + + count = 0; + + for (auto token : dictionary) { + if (offset + token.length() < 0xfffff0 && count < MAX_AUTO_EXTRAS) { + // This lenght is guranteed to be < MAX_AUTO_EXTRA + ptrhld.get()[offset++] = (uint8_t)token.length(); + memcpy(ptrhld.get() + offset, token.c_str(), token.length()); + offset += token.length(); + count++; + } + } + + // Type + ArrayType *arrayTy = ArrayType::get(IntegerType::get(Ctx, 8), offset); + // The actual dict + GlobalVariable *dict = new GlobalVariable( + M, arrayTy, true, GlobalVariable::ExternalLinkage, + ConstantDataArray::get(Ctx, + *(new ArrayRef(ptrhld.get(), offset))), + "libafl_dictionary_" + M.getName()); + dict->setSection("libafl_token"); + } + } #if USE_NEW_PM auto PA = PreservedAnalyses::all(); diff --git a/scripts/fmt_all.sh b/scripts/fmt_all.sh index 4161b497a4..57448234cf 100755 --- a/scripts/fmt_all.sh +++ b/scripts/fmt_all.sh @@ -11,7 +11,7 @@ cargo fmt echo "[*] Formatting C(pp) files" # shellcheck disable=SC2046 -clang-format-13 -i --style=file $(find . -type f \( -name '*.cpp' -o -iname '*.hpp' -o -name '*.cc' -o -name '*.cxx' -o -name '*.cc' -o -name '*.h' \) | grep -v '/target/' | grep -v 'libpng-1\.6\.37' | grep -v 'stb_image\.h' | grep -v 'dlmalloc\.c') +clang-format -i --style=file $(find . -type f \( -name '*.cpp' -o -iname '*.hpp' -o -name '*.cc' -o -name '*.cxx' -o -name '*.cc' -o -name '*.h' \) | grep -v '/target/' | grep -v 'libpng-1\.6\.37' | grep -v 'stb_image\.h' | grep -v 'dlmalloc\.c')