aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2011-03-21 03:45:26 -0400
committerJeff Garzik <jgarzik@pobox.com>2011-03-21 03:45:26 -0400
commit144cf62d7c3eed3f5412edb18b238b2c1209f4c1 (patch)
tree7aa6f3fddff27ad1f72bd1cab2595979ee7e596c
parentd49d639269648394ceab175aaa8ffea876e29f4b (diff)
Avoid potential for div-by-zero, when calculating max-nonce
-rw-r--r--cpu-miner.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/cpu-miner.c b/cpu-miner.c
index e402b0b..554a297 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -585,10 +585,15 @@ static void *miner_thread(void *userdata)
hashmeter(thr_id, &diff, hashes_done);
/* adjust max_nonce to meet target scan time */
- max64 = ((uint64_t)hashes_done * opt_scantime) / diff.tv_sec;
- if (max64 > 0xfffffffaULL)
- max64 = 0xfffffffaULL;
- max_nonce = max64;
+ if (diff.tv_usec > 500000)
+ diff.tv_sec++;
+ if (diff.tv_sec > 0) {
+ max64 =
+ ((uint64_t)hashes_done * opt_scantime) / diff.tv_sec;
+ if (max64 > 0xfffffffaULL)
+ max64 = 0xfffffffaULL;
+ max_nonce = max64;
+ }
/* if nonce found, submit work */
if (rc && !submit_work(mythr, &work))