misc/natural_sort: avoid implementation-defined behavior in comparison
Before a7158ceec0, string comparision was
done with strcmp, which does unsigned comparison. The natural sort
implementation instead compares on char values.
This causes implementation-defined behavior in comparison, depending on
the signedness of char type.
Fix this by using unsigned comparison instead.
This commit is contained in:
1 parent
4574644b7a
commit
ea03451d1e
1 file changed
+2
-2
+2
-2
@@ -51,9 +51,9 @@ int mp_natural_sort_cmp(const char *name1, const char *name2)
|
||||
name2++;
|
||||
}
|
||||
} else {
|
||||
if (mp_tolower(name1[0]) < mp_tolower(name2[0]))
|
||||
if ((unsigned char)mp_tolower(name1[0]) < (unsigned char)mp_tolower(name2[0]))
|
||||
return -1;
|
||||
if (mp_tolower(name1[0]) > mp_tolower(name2[0]))
|
||||
if ((unsigned char)mp_tolower(name1[0]) > (unsigned char)mp_tolower(name2[0]))
|
||||
return 1;
|
||||
name1++;
|
||||
name2++;
|
||||
|
||||
Reference in new issue
Block a user