[libFuzzer] make LLVMFuzzerTestOneInput (the fuzzer target function) return int inste...
[oota-llvm.git] / lib / Fuzzer / FuzzerInterface.h
index 7f7d608800d166fa4703591716974fd4769af8eb..de5084222ef4539e317d5743f47bec329e15e573 100644 (file)
@@ -23,7 +23,9 @@
 
 namespace fuzzer {
 
-typedef void (*UserCallback)(const uint8_t *Data, size_t Size);
+typedef void (*DeprecatedUserCallback)(const uint8_t *Data, size_t Size);
+/// Returns an int 0. Values other than zero are reserved for future.
+typedef int (*UserCallback)(const uint8_t *Data, size_t Size);
 /** Simple C-like interface with a single user-supplied callback.
 
 Usage:
@@ -31,8 +33,9 @@ Usage:
 #\code
 #include "FuzzerInterface.h"
 
-void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   DoStuffWithData(Data, Size);
+  return 0;
 }
 
 // Implement your own main() or use the one from FuzzerMain.cpp.
@@ -43,6 +46,7 @@ int main(int argc, char **argv) {
 #\endcode
 */
 int FuzzerDriver(int argc, char **argv, UserCallback Callback);
+int FuzzerDriver(int argc, char **argv, DeprecatedUserCallback Callback);
 
 class FuzzerRandomBase {
  public:
@@ -118,7 +122,7 @@ class MyFuzzer : public fuzzer::UserSuppliedFuzzer {
  public:
   MyFuzzer(fuzzer::FuzzerRandomBase *Rand);
   // Must define the target function.
-  void TargetFunction(...) { ... }
+  int TargetFunction(...) { ...; return 0; }
   // Optionally define the mutator.
   size_t Mutate(...) { ... }
   // Optionally define the CrossOver method.
@@ -136,7 +140,7 @@ class UserSuppliedFuzzer {
   UserSuppliedFuzzer();  // Deprecated, don't use.
   UserSuppliedFuzzer(FuzzerRandomBase *Rand);
   /// Executes the target function on 'Size' bytes of 'Data'.
-  virtual void TargetFunction(const uint8_t *Data, size_t Size) = 0;
+  virtual int TargetFunction(const uint8_t *Data, size_t Size) = 0;
   /// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
   /// returns the new size of the data, which should be positive.
   virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize) {