From: Zbigniew Jędrzejewski-Szmek Date: Tue, 17 May 2022 12:19:19 +0000 (+0200) Subject: fundamental: make strverscmp_improved() return -1/0/+1 in all cases X-Git-Tag: v252-rc1~939^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbf43adce2863e4362d6fa286bf77fd2dc47cdc1;p=thirdparty%2Fsystemd.git fundamental: make strverscmp_improved() return -1/0/+1 in all cases We would return the result of strcmp(), i.e. some positive/negative value. Now that we want to make this a documented interface for other people to implement, let's make the implementation more contstrained, even if we ourselves don't care about whether the specific values. --- diff --git a/src/fundamental/string-util-fundamental.c b/src/fundamental/string-util-fundamental.c index 0d8a820bacb..57b4d535f3a 100644 --- a/src/fundamental/string-util-fundamental.c +++ b/src/fundamental/string-util-fundamental.c @@ -126,7 +126,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { */ if (isempty(a) || isempty(b)) - return strcmp_ptr(a, b); + return CMP(strcmp_ptr(a, b), 0); for (;;) { const sd_char *aa, *bb; @@ -208,7 +208,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { return r; /* Then, compare them as strings. */ - r = strncmp(a, b, aa - a); + r = CMP(strncmp(a, b, aa - a), 0); if (r != 0) return r; } else { @@ -219,7 +219,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { ; /* Note that the segments are usually not NUL-terminated. */ - r = strncmp(a, b, MIN(aa - a, bb - b)); + r = CMP(strncmp(a, b, MIN(aa - a, bb - b)), 0); if (r != 0) return r;