From: Rich Felker Date: Tue, 26 Feb 2013 06:42:11 +0000 (-0500) Subject: fix integer type issue in strverscmp X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=commitdiff_plain;h=5afc74fbaa2371f30df0dc9fb7bc3afe6bd96137 fix integer type issue in strverscmp lenl-lenr is not a valid expression for a signed int return value from strverscmp, since after implicit conversion from size_t to int this difference could have the wrong sign or might even be zero. using the difference for char values works since they're bounded well within the range of differences representable by int, but it does not work for size_t values. --- diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c index 33a42eed..94d2e15c 100644 --- a/src/string/strverscmp.c +++ b/src/string/strverscmp.c @@ -31,8 +31,10 @@ int strverscmp(const char *l, const char *r) while (isdigit(r[lenr]) ) lenr++; if (lenl==lenr) { return (*l - *r); + } else if (lenl>lenr) { + return 1; } else { - return (lenl - lenr); + return -1; } } else { return (*l - *r);