From: Roland Haeder <roland@mxchange.org>
Date: Mon, 31 Mar 2014 18:43:40 +0000 (+0200)
Subject: Taken care of possible usage of uninitialized variable $hashrate.
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6abb05749348fe89e45c9a69cfec0c3e50040358;p=core.git

Taken care of possible usage of uninitialized variable $hashrate.

Signed-off-by: Roland Häder <roland@mxchange.org>
---

diff --git a/contrib/chash/chash.php b/contrib/chash/chash.php
index 7101f3dc..fe490dbb 100644
--- a/contrib/chash/chash.php
+++ b/contrib/chash/chash.php
@@ -241,8 +241,9 @@ $totalBlocks = 0;
 $nonce = 1 / mt_rand();
 
 while (TRUE) {
-	// Init hash-per-block counter
+	// Init hash-per-block counter and hashrate
 	$hashesPerBlock = 0;
+	$hashrate = 0;
 
 	// Wait for BLOCK_SIZE iterations (= found hashes). This is one block
 	$timeBlock = microtime(TRUE);
@@ -321,6 +322,12 @@ while (TRUE) {
 	//print ('calculateSumFromHash(modulaHash)=' . calculateSumFromHash($modulaHash) . PHP_EOL);
 	//print ('calculateSumFromHash(nonceHash)=' . calculateSumFromHash($nonceHash) . PHP_EOL);
 
+	// Is the hash rate unset?
+	if ($hashrate == 0) {
+		// Then calculate it again
+		$hashrate = 1 / $timeBlock * $iter * 2 + 2;
+	} // END - if
+
 	// Calculate reward
 	$reward = abs($timeBlock - $timeBadHashes) / $hashrate * $hashesPerBlock / BLOCK_SIZE * 1000;
 	print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $hashesPerBlock .',reward=' . $reward . PHP_EOL);
@@ -330,8 +337,8 @@ while (TRUE) {
 	$totalBlocks++;
 	$hashesPerBlock = 0;
 
-	// Calculate next hash from both hashes
-	$modulaHash = doubleHashString(modulaHash($nonceHash, $modulaHash));
+	// Use nonceHash as next modula hash
+	$modulaHash = $nonceHash;
 
 	// Calculate new nonce
 	$nonce = calculateNonce($nonce);