Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/core/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function write_log($level, $msg)

$message .= $this->_format_line($level, $date, $msg);

for ($written = 0, $length = self::strlen($message); $written < $length; $written += $result)
for ($result = $written = 0, $length = self::strlen($message); $written < $length; $written += $result)
{
if (($result = fwrite($fp, self::substr($message, $written))) === FALSE)
{
Expand Down
21 changes: 21 additions & 0 deletions tests/codeigniter/core/Log_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,25 @@ public function test_format_line()
"LEVEL - Timestamp --> Message".PHP_EOL
);
}

public function test_write_log_with_empty_message()
{
$this->ci_set_config('log_path', '');
$this->ci_set_config('log_threshold', 4);
$this->ci_set_config('log_filename', 'empty.log');
$instance = new Log_empty_format_stub();

// _format_line() is overridden to return '', so $message is empty and the
// write loop never runs. Without $result initialised, is_int($result) returns FALSE,
// and write_log() wrongly returns FALSE.
$this->assertTrue($instance->write_log('error', 'discarded'));
}
}

class Log_empty_format_stub extends CI_Log {

protected function _format_line($level, $date, $message)
{
return '';
}
}
Loading