From f58d54e77b92c55d42486b0be7758ecee7aaf5e8 Mon Sep 17 00:00:00 2001 From: Doug Freed Date: Wed, 12 Oct 2022 21:43:52 -0400 Subject: [PATCH] pkg: make pkgconf_compare_version consistent The code taken from rpmvercmp in pkg-config returns -1 if a is less than b, 0 if a is equal to b, and 1 if a is greater than b. This matches the expectations of the comparison operators that use this function. However, the tilde handling, the NULL handling, and the docstring all do the opposite. This fixes the tilde handling, the NULL handling, and the docstring to match the behavior of the rpmvercmp code and the expectations of the comparison operators. --- libpkgconf/pkg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index f71f508..0150852 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -798,7 +798,7 @@ out: * * :param char* a: The first version to compare in the pair. * :param char* b: The second version to compare in the pair. - * :return: -1 if the first version is greater, 0 if both versions are equal, 1 if the second version is greater. + * :return: -1 if the first version is less than, 0 if both versions are equal, 1 if the second version is less than. * :rtype: int */ int @@ -813,10 +813,10 @@ pkgconf_compare_version(const char *a, const char *b) /* optimization: if version matches then it's the same version. */ if (a == NULL) - return 1; + return -1; if (b == NULL) - return -1; + return 1; if (!strcasecmp(a, b)) return 0; @@ -837,9 +837,9 @@ pkgconf_compare_version(const char *a, const char *b) if (*one == '~' || *two == '~') { if (*one != '~') - return -1; - if (*two != '~') return 1; + if (*two != '~') + return -1; one++; two++;