Skip to content

Commit

Permalink
Avoid modifying pass-by-reference string in stream.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronschmitz committed Apr 25, 2012
1 parent 49e6ac3 commit 8c929db
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libraries/joomla/filesystem/stream.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -773,12 +773,13 @@ public function write(&$string, $length = 0, $chunk = 0)
$track_errors = ini_get('track_errors'); $track_errors = ini_get('track_errors');
ini_set('track_errors', true); ini_set('track_errors', true);
$remaining = $length; $remaining = $length;
$start = 0;


do do
{ {
// If the amount remaining is greater than the chunk size, then use the chunk // If the amount remaining is greater than the chunk size, then use the chunk
$amount = ($remaining > $chunk) ? $chunk : $remaining; $amount = ($remaining > $chunk) ? $chunk : $remaining;
$res = fwrite($this->_fh, $string, $amount); $res = fwrite($this->_fh, substr($string, $start), $amount);


// Returns false on error or the number of bytes written // Returns false on error or the number of bytes written
if ($res === false) if ($res === false)
Expand All @@ -797,7 +798,7 @@ public function write(&$string, $length = 0, $chunk = 0)
else else
{ {
// Wrote something // Wrote something
$string = substr($string, $amount); $start += $amount;
$remaining -= $res; $remaining -= $res;
} }
} }
Expand Down

0 comments on commit 8c929db

Please sign in to comment.