[PATCH 3/5] rpmvercmp: Return -1/0/1 as function says it will

Dan Nicholson dbn.lists at gmail.com
Sat Apr 20 09:41:56 PDT 2013


strcmp is only guaranteed to return !0 when the strings are unmatched
while rpmvercmp says it will return only -1 or 1 in those cases.

pkg-config currently only checks for !0, so this doesn't actually fix
any issues here. However, this is harmless and helps minimize the diff
with upstream rpmvercmp.

http://rpm.org/gitweb?p=rpm.git;a=commitdiff;h=ee64849e
---
 rpmvercmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rpmvercmp.c b/rpmvercmp.c
index 6de5c02..648026c 100644
--- a/rpmvercmp.c
+++ b/rpmvercmp.c
@@ -106,7 +106,7 @@ int rpmvercmp(const char * a, const char * b)
 	/* if they are equal because there might be more segments to */
 	/* compare */
 	rc = strcmp(one, two);
-	if (rc) return rc;
+	if (rc) return (rc < 1 ? -1 : 1);
 
 	/* restore character that was replaced by null above */
 	*str1 = oldch1;
-- 
1.8.1.4



More information about the pkg-config mailing list