Skip to content

Commit

Permalink
Prevent string index underrun
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and sebastianbergmann committed Oct 30, 2024
1 parent 860c0f2 commit 8c4071f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ScalarComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ private static function findCommonSuffix(string $string1, string $string2): stri
return '';
}

while ($string1[$lastCharIndex1] == $string2[$lastCharIndex2]) {
while (
$lastCharIndex1 > 0 &&
$lastCharIndex2 > 0 &&
$string1[$lastCharIndex1] == $string2[$lastCharIndex2]
) {
$lastCharIndex1--;
$lastCharIndex2--;
}
Expand Down

0 comments on commit 8c4071f

Please sign in to comment.