summaryrefslogtreecommitdiffstats
path: root/ossfuzz/compress_fuzzer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ossfuzz/compress_fuzzer.cc')
-rw-r--r--ossfuzz/compress_fuzzer.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/ossfuzz/compress_fuzzer.cc b/ossfuzz/compress_fuzzer.cc
index 006a0ab..4a720e2 100644
--- a/ossfuzz/compress_fuzzer.cc
+++ b/ossfuzz/compress_fuzzer.cc
@@ -3,20 +3,24 @@
#include <stdlib.h>
#include "lz4.h"
+#define CHECK(COND) if (!(COND)) { abort(); }
+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
size_t const compressed_dest_size = LZ4_compressBound(size);
char *const dest_buffer = (char *)malloc(compressed_dest_size);
- int result = LZ4_compress_default((const char*)data, dest_buffer,
- size, compressed_dest_size);
-
- if (result == 0)
+ if (dest_buffer != NULL)
{
- abort();
- }
+ // Allocation succeeded, try compressing the incoming data.
+ int result = LZ4_compress_default((const char*)data,
+ dest_buffer,
+ size,
+ compressed_dest_size);
+ CHECK(result != 0);
- free(dest_buffer);
+ free(dest_buffer);
+ }
return 0;
}