1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add range check

This commit is contained in:
Matt Brown 2020-10-15 13:04:24 -04:00 committed by Daniil Gentili
parent 5b140bf522
commit 1025b29e06
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7

View File

@ -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;