LLVM coverage making it more C++ too.
diff --git a/instrumentation/SanitizerCoverageLTO.so.cc b/instrumentation/SanitizerCoverageLTO.so.cc
index eb0f06b..960eb78 100644
--- a/instrumentation/SanitizerCoverageLTO.so.cc
+++ b/instrumentation/SanitizerCoverageLTO.so.cc
@@ -1065,7 +1065,6 @@
if (dictionary.size()) {
size_t memlen = 0, count = 0, offset = 0;
- char * ptr;
// sort and unique the dictionary
std::sort(dictionary.begin(), dictionary.end());
@@ -1085,13 +1084,7 @@
if (count) {
- if ((ptr = (char *)malloc(memlen + count)) == NULL) {
-
- fprintf(stderr, "Error: malloc for %lu bytes failed!\n",
- memlen + count);
- exit(-1);
-
- }
+ auto ptrhld = std::unique_ptr<char []>(new char[memlen + count]);
count = 0;
@@ -1099,8 +1092,8 @@
if (offset + token.length() < 0xfffff0 && count < MAX_AUTO_EXTRAS) {
- ptr[offset++] = (uint8_t)token.length();
- memcpy(ptr + offset, token.c_str(), token.length());
+ ptrhld.get()[offset++] = (uint8_t)token.length();
+ memcpy(ptrhld.get() + offset, token.c_str(), token.length());
offset += token.length();
count++;
@@ -1120,10 +1113,10 @@
GlobalVariable *AFLInternalDictionary = new GlobalVariable(
M, ArrayTy, true, GlobalValue::ExternalLinkage,
ConstantDataArray::get(Ctx,
- *(new ArrayRef<char>((char *)ptr, offset))),
+ *(new ArrayRef<char>(ptrhld.get(), offset))),
"__afl_internal_dictionary");
AFLInternalDictionary->setInitializer(ConstantDataArray::get(
- Ctx, *(new ArrayRef<char>((char *)ptr, offset))));
+ Ctx, *(new ArrayRef<char>(ptrhld.get(), offset))));
AFLInternalDictionary->setConstant(true);
GlobalVariable *AFLDictionary = new GlobalVariable(