summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-02-26 01:42:11 -0500
committerRich Felker <dalias@aerifal.cx>2013-02-26 01:42:11 -0500
commit5afc74fbaa2371f30df0dc9fb7bc3afe6bd96137 (patch)
treef42067ddc2e612f5e4f01174c8b22b2ecc04acec /src
parent4853c1f7f7b5023aa6a409abc1e759f5f92c9c4e (diff)
downloadmusl-5afc74fbaa2371f30df0dc9fb7bc3afe6bd96137.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/string/strverscmp.c4
1 files changed, 3 insertions, 1 deletions
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);