From dbf43adce2863e4362d6fa286bf77fd2dc47cdc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 17 May 2022 14:19:19 +0200 Subject: [PATCH] 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. --- src/fundamental/string-util-fundamental.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; -- 2.47.3