Skip to content

Commit 038512f

Browse files
committed
Fix version comparison in Version.pm
Version strings with unequal numbers of parts were being compared incorrectly. We cure this by treating a missing part in the shorter version as 0. per complaint from Jehan-Guillaume de Rorthais, but the fix is mine, not his. Discussion: https://postgr.es/m/20220628225325.53d97b8d@karst Backpatch to release 14 where this code was introduced.
1 parent 32d5a49 commit 038512f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/test/perl/PostgresVersion.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ sub _version_cmp
120120

121121
for (my $idx = 0;; $idx++)
122122
{
123-
return 0 unless (defined $an->[$idx] && defined $bn->[$idx]);
124-
return $an->[$idx] <=> $bn->[$idx]
125-
if ($an->[$idx] <=> $bn->[$idx]);
123+
return 0
124+
if ($idx >= @$an && $idx >= @$bn);
125+
# treat a missing number as 0
126+
my ($anum, $bnum) = ($an->[$idx] || 0, $bn->[$idx] || 0);
127+
return $anum <=> $bnum
128+
if ($anum <=> $bnum);
126129
}
127130
}
128131

0 commit comments

Comments
 (0)