Bug#350793: htons() has wrong type at -O
Package: libc6.1-dev
Version: 2.3.5-12
Severity: normal
File: /usr/include/arpa/inet.h
falk@juist:/tmp% cat test.c
#include <arpa/inet.h>
int f() { return ntohs(1) > 1u; }
falk@juist:/tmp% gcc -c -W test.c
falk@juist:/tmp% gcc -c -W -O test.c
test.c: In function 'f':
test.c:2: warning: comparison between signed and unsigned
This is because htons is inlined to:
int f() { return (__extension__ ({ unsigned short int __bsx = (1); ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); })) > 1u; }
and because of C's promotion rules, the ({}) expression has type
signed int. However, htons is supposed to return uint16_t.
This makes nepenthes FTBFS (it has -Werror). I tried to imagine a
situation where it might lead to wrong code, but couldn't think of
one, short of taking sizeof htons().
Falk
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: alpha
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.13.2
Locale: LANG=C, LC_CTYPE=de_DE@euro (charmap=ISO-8859-15)
Versions of packages libc6.1-dev depends on:
ii libc6.1 2.3.5-12 GNU C Library: Shared libraries an
ii linux-kernel-headers 2.6.13+0rc3-2 Linux Kernel Headers for developme
Versions of packages libc6.1-dev recommends:
ii gcc [c-compiler] 4:4.0.2-2 The GNU C compiler
ii gcc-3.3 [c-compiler] 1:3.3.6-12 The GNU C compiler
ii gcc-4.0 [c-compiler] 4.0.2-8 The GNU C compiler
-- no debconf information
Reply to: