From 6abb05749348fe89e45c9a69cfec0c3e50040358 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 31 Mar 2014 20:43:40 +0200 Subject: [PATCH] Taken care of possible usage of uninitialized variable $hashrate. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- contrib/chash/chash.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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); -- 2.39.5