aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2022-11-18 08:38:26 -0500
committerAndrew Dunstan <andrew@dunslane.net>2022-11-18 08:47:31 -0500
commitdf4e93bea4f9370c14f01d27e6d36cbe7afaac72 (patch)
tree5666cd34ac504aad8225f28f74694b56be7472de /src
parent3d45edcef0e141f2a17a21d0411efa889f843b00 (diff)
downloadpostgresql-df4e93bea4f9370c14f01d27e6d36cbe7afaac72.tar.gz
postgresql-df4e93bea4f9370c14f01d27e6d36cbe7afaac72.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/test/perl/PostgreSQL/Version.pm9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/test/perl/PostgreSQL/Version.pm b/src/test/perl/PostgreSQL/Version.pm
index 8f704911895..8d4dbbf6948 100644
--- a/src/test/perl/PostgreSQL/Version.pm
+++ b/src/test/perl/PostgreSQL/Version.pm
@@ -123,9 +123,12 @@ sub _version_cmp
for (my $idx = 0;; $idx++)
{
- return 0 unless (defined $an->[$idx] && defined $bn->[$idx]);
- return $an->[$idx] <=> $bn->[$idx]
- if ($an->[$idx] <=> $bn->[$idx]);
+ return 0
+ if ($idx >= @$an && $idx >= @$bn);
+ # treat a missing number as 0
+ my ($anum, $bnum) = ($an->[$idx] || 0, $bn->[$idx] || 0);
+ return $anum <=> $bnum
+ if ($anum <=> $bnum);
}
}