Skip to content

Commit 5acbd43

Browse files
fix: cmpfunc prefix overlap sorting and avoid integer truncation
1 parent afbe098 commit 5acbd43

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

trurl.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,10 @@ static void qpair2query(CURLU *uh, struct option *o)
15951595
/* sort case insensitively */
15961596
static int cmpfunc(const void *p1, const void *p2)
15971597
{
1598-
int i;
1598+
size_t i;
15991599
size_t len1 = ((const struct string *)p1)->len;
16001600
size_t len2 = ((const struct string *)p2)->len;
1601-
int len = (int)(len1 < len2 ? len1 : len2);
1601+
size_t len = len1 < len2 ? len1 : len2;
16021602

16031603
for(i = 0; i < len; i++) {
16041604
char c1 = ((const struct string *)p1)->str[i] | ('a' - 'A');
@@ -1607,9 +1607,7 @@ static int cmpfunc(const void *p1, const void *p2)
16071607
return c1 - c2;
16081608
}
16091609

1610-
if(len1 != len2)
1611-
return len1 < len2 ? -1 : 1;
1612-
return 0;
1610+
return (len1 > len2) - (len1 < len2);
16131611
}
16141612

16151613
static bool sortquery(struct option *o)

0 commit comments

Comments
 (0)