1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Add range check

This commit is contained in:
Matt Brown 2020-10-15 13:04:24 -04:00
parent bf569d1b07
commit a1ca7ac4a4

View File

@ -23,7 +23,7 @@ class FileManipulation
/** @var bool */
public $remove_trailing_newline;
public function __construct(
int $start,
int $end,
@ -59,7 +59,10 @@ class FileManipulation
}
}
if ($this->remove_trailing_newline && $existing_contents[$this->end] === "\n") {
if ($this->remove_trailing_newline
&& strlen($existing_contents) > $this->end
&& $existing_contents[$this->end] === "\n"
) {
$newline_pos = strrpos($existing_contents, "\n", $this->start - strlen($existing_contents));
$newline_pos = $newline_pos !== false ? $newline_pos + 1 : 0;