libfuzzer: fix compiler warnings
authorDmitry Vyukov <dvyukov@google.com>
Wed, 2 Mar 2016 09:54:40 +0000 (09:54 +0000)
committerDmitry Vyukov <dvyukov@google.com>
Wed, 2 Mar 2016 09:54:40 +0000 (09:54 +0000)
- unused sigaction/setitimer result (used in assert)
- unchecked fscanf return value
- signed/unsigned comparison

llvm-svn: 262472

llvm/lib/Fuzzer/FuzzerTraceState.cpp
llvm/lib/Fuzzer/FuzzerUtil.cpp

index d9963682fdfe0ad59b785571ec9d4df891669a48..dc4f18c353ae7f5a105a4f986f54b7c7011b1dc8 100644 (file)
@@ -319,7 +319,7 @@ void TraceState::DFSanCmpCallback(uintptr_t PC, size_t CmpSize, size_t CmpType,
     AddMutation(Pos, CmpSize, Data - 1);
   }
 
-  if (CmpSize > LR.End - LR.Beg)
+  if (CmpSize > (size_t)(LR.End - LR.Beg))
     AddMutation(LR.Beg, (unsigned)(LR.End - LR.Beg), Data);
 
 
index 9364955b3052795ca34e658985ccb76c4e37f5dc..84c4983f991f8cb710caf24f1f0b1fe17cf2b383 100644 (file)
@@ -19,6 +19,7 @@
 #include <signal.h>
 #include <sstream>
 #include <unistd.h>
+#include <errno.h>
 
 namespace fuzzer {
 
@@ -84,14 +85,18 @@ static void SetSigaction(int signum,
   struct sigaction sigact;
   memset(&sigact, 0, sizeof(sigact));
   sigact.sa_sigaction = callback;
-  int Res = sigaction(signum, &sigact, 0);
-  assert(Res == 0);
+  if (sigaction(signum, &sigact, 0)) {
+    Printf("libFuzzer: sigaction failed with %d\n", errno);
+    exit(1);
+  }
 }
 
 void SetTimer(int Seconds) {
   struct itimerval T {{Seconds, 0}, {Seconds, 0}};
-  int Res = setitimer(ITIMER_REAL, &T, nullptr);
-  assert(Res == 0);
+  if (setitimer(ITIMER_REAL, &T, nullptr)) {
+    Printf("libFuzzer: setitimer failed with %d\n", errno);
+    exit(1);
+  }
   SetSigaction(SIGALRM, AlarmHandler);
 }
 
@@ -105,7 +110,8 @@ void SetSigIntHandler() { SetSigaction(SIGINT, InterruptHandler); }
 int NumberOfCpuCores() {
   FILE *F = popen("nproc", "r");
   int N = 0;
-  fscanf(F, "%d", &N);
+  if (fscanf(F, "%d", &N) != 1)
+    N = 1;
   fclose(F);
   return N;
 }