-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More array fixes #8943
More array fixes #8943
Conversation
Whoops, the logic is actually incorrect, hang on... |
One very nasty remaining baseline issue is caused by #8949, the rest is caused by false positives |
Thanks! |
Not sure if worth investigating, but consider checking the baseline additions @ laminas/laminas-validator#166, @danog I think what's happening here is that Psalm cannot determine the type of $decoded = [];
$separator = strrpos($encoded, '-');
if ($separator > 0) {
for ($x = 0; $x < $separator; ++$x) {
// prepare decoding matrix
$decoded[] = ord($encoded[$x]);
}
}
$lengthd = count($decoded);
$lengthe = strlen($encoded);
// decoding
$init = true;
$base = 72;
$index = 0;
$char = 0x80;
for ($indexe = $separator ? $separator + 1 : 0; $indexe < $lengthe; ++$lengthd) {
for ($oldIndex = $index, $pos = 1, $key = 36; 1; $key += 36) {
$hex = ord($encoded[$indexe++]);
$digit = $hex - 48 < 10 ? $hex - 22
: ($hex - 65 < 26 ? $hex - 65
: ($hex - 97 < 26 ? $hex - 97
: 36));
$index += $digit * $pos;
$tag = $key <= $base ? 1 : ($key >= $base + 26 ? 26 : $key - $base);
if ($digit < $tag) {
break;
}
$pos = (int) ($pos * (36 - $tag));
}
$delta = intval($init ? ($index - $oldIndex) / 700 : ($index - $oldIndex) / 2);
$delta += intval($delta / ($lengthd + 1));
for ($key = 0; $delta > 910 / 2; $key += 36) {
$delta = intval($delta / 35);
}
$base = intval($key + 36 * $delta / ($delta + 38));
$init = false;
$char += (int) ($index / ($lengthd + 1));
$index %= $lengthd + 1;
if ($lengthd > 0) {
for ($i = $lengthd; $i > $index; $i--) {
$decoded[$i] = $decoded[$i - 1];
}
}
$decoded[$index++] = $char;
} For now, I'm OK with adding it to the baseline, but I think this patch may have led to this tiny regression :-) |
@Ocramius Hmm, mind opening a new issue for this one? |
I found these snippets: https://psalm.dev/r/8adf377b9f<?php
/** @var string */
$encoded = '';
$decoded = [];
$separator = strrpos($encoded, '-');
if ($separator > 0) {
for ($x = 0; $x < $separator; ++$x) {
// prepare decoding matrix
$decoded[] = ord($encoded[$x]);
}
}
$lengthd = count($decoded);
$lengthe = strlen($encoded);
// decoding
$init = true;
$base = 72;
$index = 0;
$char = 0x80;
for ($indexe = $separator ? $separator + 1 : 0; $indexe < $lengthe; ++$lengthd) {
for ($oldIndex = $index, $pos = 1, $key = 36; 1; $key += 36) {
$hex = ord($encoded[$indexe++]);
$digit = $hex - 48 < 10 ? $hex - 22
: ($hex - 65 < 26 ? $hex - 65
: ($hex - 97 < 26 ? $hex - 97
: 36));
$index += $digit * $pos;
$tag = $key <= $base ? 1 : ($key >= $base + 26 ? 26 : $key - $base);
if ($digit < $tag) {
break;
}
$pos = (int) ($pos * (36 - $tag));
}
$delta = intval($init ? ($index - $oldIndex) / 700 : ($index - $oldIndex) / 2);
$delta += intval($delta / ($lengthd + 1));
for ($key = 0; $delta > 910 / 2; $key += 36) {
$delta = intval($delta / 35);
}
$base = intval($key + 36 * $delta / ($delta + 38));
$init = false;
$char += (int) ($index / ($lengthd + 1));
$index %= $lengthd + 1;
if ($lengthd > 0) {
for ($i = $lengthd; $i > $index; $i--) {
$decoded[$i] = $decoded[$i - 1];
}
}
$decoded[$index++] = $char;
}
/** @psalm-trace $decoded */;
|
We really should add support for disjoint arrays...