I reported this bug to Apple a couple of years ago. Maybe it was inherited from FreeBSD. The source of the problem is ntohs/htons optimization. ntohs expands to (__builtin_constant_p(_x) ? __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x)) in /usr/include/machine/endian.h. The problem is that the promoted type of that ternary expression is int. But ntohs and htons are defined to have a return type of uint16_t. Normally, this is a case of no harm no foul because basically every value gets promoted to int eventually, when used as an operand or argument. Nonetheless, the clang printf analyzer complains when using the %hu format specifier. GCC keeps silent, which is probably why this issue never came to anybody's attention. $ make CC=clang foo clang -O2 -pipe foo.c -o foo foo.c:8:12: warning: conversion specifies type 'unsigned short' but the argument has type 'int' [-Wformat] printf("%hu\n", ntohs(i)); ~~^ ~~~~~~~~ %d 1 warning generated. Fix: Cast the result of the __bswap16 expression to __uint16_t, either in the __ntohs/__htons macros, or in the __bswap16 macro directly like with __bswap16_const. How-To-Repeat: // make CC=clang foo #include <stdio.h> #include <arpa/inet.h> int main(void) { uint16_t i = 1234; printf("%hu\n", ntohs(i)); return 0; }
For bugs matching the following criteria: Status: In Progress Changed: (is less than) 2014-06-01 Reset to default assignee and clear in-progress tags. Mail being skipped
fixed in base r232730
Assign to committer that resolved