shithub: fuzz

Download patch

ref: f1769a8617cbae9b03c470558b253df7fdb0b471
parent: 5de3149251a5abf4ae19f3f09df7aaaaf2afd74c
author: glenda <glenda@cpre431>
date: Sun Nov 25 12:24:08 EST 2018

fix rng() ? change to return int like rand()

--- a/fuzz.h
+++ b/fuzz.h
@@ -3,7 +3,7 @@
 
 #include <u.h>
 #include <libc.h>
-#include <libsec.h>
+// #include <libsec.h>
 #include "list.h"
 #include "mutate.h"
 
@@ -10,6 +10,9 @@
 // Minimum amount of time in ms required for rand() to cycle
 #define MIN_SLEEP 128
 
+// Max signed int value
+#define MAXINT 2147483647
+
 // Number of calls in enum calls
 #define NCALLS 68
 #define NTYPES 16
@@ -169,6 +172,6 @@
 // main.c
 void	dolog(char*, ...);
 void	debug(char*, ...);
-ulong	rng(void);
+int		rng(void);
 
 #endif
--- a/main.c
+++ b/main.c
@@ -42,15 +42,16 @@
 }
 
 // Thread-safe sleepable random number generator
-ulong
+int
 rng(void)
 {
-	ulong n;
+	ulong x;
 	lock(&rnglck);
-	n = fastrand();
-	sleep(MIN_SLEEP);
+	// Generate a number: 0 ≤ x ≤ MAXINT
+	x = nrand(MAXINT);
+	debug("DEBUG: Generated num is: %d\n", x);
 	unlock(&rnglck);
-	return n;
+	return x;
 }
 
 /* Prototypes */
@@ -98,8 +99,6 @@
 		exits("log file create fail");
 	}
 
-	// save so we don't have two different time(0)'s
-	//int fuzz_seed = time(0);
 	int fuzz_seed = truerand();
 	srand(fuzz_seed);
 	dolog("== Seed Value: %d ==\n", fuzz_seed);