Commit e95b42ea54d2989659232560a9932b676e801604

Con Kolivas 2013-11-02T08:46:13

Add a sanity check to avoid divide by zero crashes in set_target

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/cgminer.c b/cgminer.c
index b58476d..95de19c 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5926,6 +5926,12 @@ void set_target(unsigned char *dest_target, double diff)
 	uint64_t *data64, h64;
 	double d64, dcut64;
 
+	if (unlikely(diff == 0.0)) {
+		/* This shouldn't happen but best we check to prevent a crash */
+		applog(LOG_ERR, "Diff zero passed to set_target");
+		diff = 1.0;
+	}
+
 	d64 = truediffone;
 	if (opt_scrypt)
 		d64 *= (double)65536;