]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fundamental: make strverscmp_improved() return -1/0/+1 in all cases
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 May 2022 12:19:19 +0000 (14:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 May 2022 14:33:43 +0000 (16:33 +0200)
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

index 0d8a820bacb419cc0cecec7ef96c43d913c4a0a7..57b4d535f3a96f5b67e5fbb3e86e85e989e907e7 100644 (file)
@@ -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;