|
57 | 57 | struct addrinfo_sort_elem |
58 | 58 | { |
59 | 59 | struct ares_addrinfo_node *ai; |
60 | | - int has_src_addr; |
| 60 | + ares_bool_t has_src_addr; |
61 | 61 | ares_sockaddr src_addr; |
62 | | - int original_order; |
| 62 | + size_t original_order; |
63 | 63 | }; |
64 | 64 |
|
65 | 65 | #define ARES_IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) |
@@ -255,15 +255,16 @@ static int get_precedence(const struct sockaddr *addr) |
255 | 255 | /* |
256 | 256 | * Find number of matching initial bits between the two addresses a1 and a2. |
257 | 257 | */ |
258 | | -static int common_prefix_len(const struct in6_addr *a1, |
| 258 | +static size_t common_prefix_len(const struct in6_addr *a1, |
259 | 259 | const struct in6_addr *a2) |
260 | 260 | { |
261 | | - const char *p1 = (const char *)a1; |
262 | | - const char *p2 = (const char *)a2; |
263 | | - unsigned i; |
| 261 | + const unsigned char *p1 = (const unsigned char *)a1; |
| 262 | + const unsigned char *p2 = (const unsigned char *)a2; |
| 263 | + size_t i; |
264 | 264 | for (i = 0; i < sizeof(*a1); ++i) |
265 | 265 | { |
266 | | - int x, j; |
| 266 | + unsigned char x; |
| 267 | + size_t j; |
267 | 268 | if (p1[i] == p2[i]) |
268 | 269 | { |
269 | 270 | continue; |
@@ -294,12 +295,12 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2) |
294 | 295 | int label_src1, label_dst1, label_match1; |
295 | 296 | int label_src2, label_dst2, label_match2; |
296 | 297 | int precedence1, precedence2; |
297 | | - int prefixlen1, prefixlen2; |
| 298 | + size_t prefixlen1, prefixlen2; |
298 | 299 |
|
299 | 300 | /* Rule 1: Avoid unusable destinations. */ |
300 | 301 | if (a1->has_src_addr != a2->has_src_addr) |
301 | 302 | { |
302 | | - return a2->has_src_addr - a1->has_src_addr; |
| 303 | + return ((int)a2->has_src_addr) - ((int)a1->has_src_addr); |
303 | 304 | } |
304 | 305 |
|
305 | 306 | /* Rule 2: Prefer matching scope. */ |
@@ -372,22 +373,22 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2) |
372 | 373 | prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr); |
373 | 374 | if (prefixlen1 != prefixlen2) |
374 | 375 | { |
375 | | - return prefixlen2 - prefixlen1; |
| 376 | + return (int)prefixlen2 - (int)prefixlen1; |
376 | 377 | } |
377 | 378 | } |
378 | 379 |
|
379 | 380 | /* |
380 | 381 | * Rule 10: Leave the order unchanged. |
381 | 382 | * We need this since qsort() is not necessarily stable. |
382 | 383 | */ |
383 | | - return a1->original_order - a2->original_order; |
| 384 | + return ((int)a1->original_order) - ((int)a2->original_order); |
384 | 385 | } |
385 | 386 |
|
386 | 387 | /* |
387 | 388 | * Find the source address that will be used if trying to connect to the given |
388 | 389 | * address. |
389 | 390 | * |
390 | | - * Returns 1 if a source address was found, 0 if the address is unreachable, |
| 391 | + * Returns 1 if a source address was found, 0 if the address is unreachable |
391 | 392 | * and -1 if a fatal error occurred. If 0 or 1, the contents of src_addr are |
392 | 393 | * undefined. |
393 | 394 | */ |
@@ -454,7 +455,7 @@ ares_status_t ares__sortaddrinfo(ares_channel channel, |
454 | 455 | struct ares_addrinfo_node *list_sentinel) |
455 | 456 | { |
456 | 457 | struct ares_addrinfo_node *cur; |
457 | | - int nelem = 0, i; |
| 458 | + size_t nelem = 0, i; |
458 | 459 | int has_src_addr; |
459 | 460 | struct addrinfo_sort_elem *elems; |
460 | 461 |
|
@@ -490,7 +491,7 @@ ares_status_t ares__sortaddrinfo(ares_channel channel, |
490 | 491 | ares_free(elems); |
491 | 492 | return ARES_ENOTFOUND; |
492 | 493 | } |
493 | | - elems[i].has_src_addr = has_src_addr; |
| 494 | + elems[i].has_src_addr = (has_src_addr == 1)?ARES_TRUE:ARES_FALSE; |
494 | 495 | } |
495 | 496 |
|
496 | 497 | /* Sort the addresses, and rearrange the linked list so it matches the sorted |
|
0 commit comments