More markups for style changes
authorMax Dymond <cmeister2@gmail.com>
Fri, 28 Jun 2019 23:23:06 +0000 (00:23 +0100)
committerMax Dymond <cmeister2@gmail.com>
Fri, 28 Jun 2019 23:23:06 +0000 (00:23 +0100)
ossfuzz/Makefile
ossfuzz/compress_fuzzer.c
ossfuzz/decompress_fuzzer.c
ossfuzz/testinput.h

index 1480ccb..7812c41 100644 (file)
@@ -31,28 +31,28 @@ LIB_FUZZING_ENGINE ?= standaloneengine.o
 DEBUGLEVEL?= 1
 DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
 
-CFLAGS   += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
-CXXFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
-CPPFLAGS += -DXXH_NAMESPACE=LZ4_
+LZ4_CFLAGS  = $(CFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
+LZ4_CXXFLAGS = $(CXXFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
+LZ4_CPPFLAGS = $(CPPFLAGS) -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
 
 include ../Makefile.inc
 
 # Include a rule to build the static library if calling this target
 # directly.
 $(LZ4DIR)/liblz4.a:
-       $(MAKE) -C $(LZ4DIR) CFLAGS="$(CFLAGS)" liblz4.a
+       $(MAKE) -C $(LZ4DIR) CFLAGS="$(LZ4_CFLAGS)" liblz4.a
 
 %.o: %.c
-       $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
+       $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) $< -o $@
 
 # Generic rule for generating fuzzers
 %_fuzzer: %_fuzzer.o $(LZ4DIR)/liblz4.a
        # Compile the standalone code just in case. The OSS-Fuzz code might
        # override the LIB_FUZZING_ENGINE value to "-fsanitize=fuzzer"
-       $(CC) -c $(CFLAGS) $(CPPFLAGS) standaloneengine.c -o standaloneengine.o
+       $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) standaloneengine.c -o standaloneengine.o
 
        # Now compile the actual fuzzer.
-       $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
+       $(CXX) $(LZ4_CXXFLAGS) $(LZ4_CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
 
 %_fuzzer_clean:
        $(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o
index 28610ad..3908534 100644 (file)
@@ -10,17 +10,16 @@ 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);
 
-  if (dest_buffer != NULL)
-  {
-    // Allocation succeeded, try compressing the incoming data.
-    int result = LZ4_compress_default((const char*)data,
-                                      dest_buffer,
-                                      size,
-                                      compressed_dest_size);
-    CHECK(result != 0);
+  CHECK(dest_buffer != NULL);
 
-    free(dest_buffer);
-  }
+  // 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);
 
   return 0;
 }
index 1fa2b1a..e6e14c4 100644 (file)
@@ -7,22 +7,22 @@
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
 {
+  // TODO: Size input buffer pseudo-randomly based on seed extracted from input
   size_t const buffer_size = 10 * 1024 * 1024;
   char *const dest_buffer = (char *)malloc(buffer_size);
 
-  if (dest_buffer != NULL)
-  {
-    // Allocation succeeded, try decompressing the incoming data.
-    int result = LZ4_decompress_safe((const char*)data,
-                                     dest_buffer,
-                                     size,
-                                     buffer_size);
+  CHECK(dest_buffer != NULL);
 
-    // Ignore the result of decompression.
-    (void)result;
+  // Allocation succeeded, try decompressing the incoming data.
+  int result = LZ4_decompress_safe((const char*)data,
+                                   dest_buffer,
+                                   size,
+                                   buffer_size);
 
-    free(dest_buffer);
-  }
+  // Ignore the result of decompression.
+  (void)result;
+
+  free(dest_buffer);
 
   return 0;
 }
index 8da6215..0e50a3c 100644 (file)
@@ -1,3 +1,15 @@
+#ifndef TESTINPUT_H_INCLUDED
+#define TESTINPUT_H_INCLUDED
+
 #include <inttypes.h>
 
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif