History

misc/natural_sort: avoid implementation-defined behavior in comparison

Before a7158ceec00f14e680a885722cfe23761b4662d3, 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.

nanahi committed 2 years ago

Commit ea034511 parent 45746441 file · +2 −2Browse files

Unified · Split

misc/natural_sort.c+2−2
@@ -51,9 +51,9 @@ int mp_natural_sort_cmp(const char *name1, const char *name2) · 50 unmodified lines
51 name2++;51 name2++;
52 }52 }
53 } else {53 } else {
54 if (mp_tolower(name1[0]) < mp_tolower(name2[0]))54 if ((unsigned char)mp_tolower(name1[0]) < (unsigned char)mp_tolower(name2[0]))
55 return -1;55 return -1;
56 if (mp_tolower(name1[0]) > mp_tolower(name2[0]))56 if ((unsigned char)mp_tolower(name1[0]) > (unsigned char)mp_tolower(name2[0]))
57 return 1;57 return 1;
58 name1++;58 name1++;
59 name2++;59 name2++;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t