]> git.mxchange.org Git - hub.git/commitdiff
Missed to initialize arrays before pushing new entries on them. This might be a candi...
authorRoland Häder <roland@mxchange.org>
Sat, 4 May 2013 16:38:09 +0000 (16:38 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 4 May 2013 16:38:09 +0000 (16:38 +0000)
application/hub/main/package/fragmenter/class_PackageFragmenter.php

index 277083d6e3966ea831a84ab4eb5be034ca5f62d1..7214942cf8e8f5d3d18fb8b9d755388b64272578 100644 (file)
@@ -279,7 +279,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                 * Get the crypto instance and hash the data with no extra salt because
                 * the other peer doesn't have *this* peer's salt.
                 */
-               $hash = $this->getCryptoInstance()->hashString($rawData, '', false);
+               $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE);
 
                // Return it
                return $hash;
@@ -354,9 +354,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $prepend        Whether append (default) or prepend the chunk
         * @return      void
         */
-       private function addChunkData ($finalHash, $chunkData, $prepend = false) {
+       private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) {
                // Hash it
-               $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', false);
+               $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE);
 
                // Prepend the hash to the chunk
                $rawData = (
@@ -370,7 +370,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackage::TCP_PACKAGE_SIZE);
 
                // Add it to the array
-               if ($prepend === true) {
+               if ($prepend === TRUE) {
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ': Prepending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
                        array_unshift($this->chunkHashes[$finalHash], $rawDataHash);
@@ -378,7 +378,16 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                } else {
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ': Appending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
-                       $this->chunks[$finalHash][]      = $rawData;
+
+                       // Is the array there?
+                       if (!isset($this->chunks[$finalHash])) {
+                               // Then initialize it
+                               $this->chunks[$finalHash]      = array();
+                               $this->chunkHashes[$finalHash] = array();
+                       } // END - if
+
+                       // Add both
+                       array_push($this->chunks[$finalHash]     , $rawData);
                        array_push($this->chunkHashes[$finalHash], $rawDataHash);
                }
        }