mirror of
https://github.com/fluencelabs/musl
synced 2025-06-26 05:02:02 +00:00
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.
This commit is contained in:
@ -31,8 +31,10 @@ int strverscmp(const char *l, const char *r)
|
|||||||
while (isdigit(r[lenr]) ) lenr++;
|
while (isdigit(r[lenr]) ) lenr++;
|
||||||
if (lenl==lenr) {
|
if (lenl==lenr) {
|
||||||
return (*l - *r);
|
return (*l - *r);
|
||||||
|
} else if (lenl>lenr) {
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return (lenl - lenr);
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return (*l - *r);
|
return (*l - *r);
|
||||||
|
Reference in New Issue
Block a user