Bug#751409: libc6-dev: endian.h macros don't always return the correct type
Package: libc6-dev
Version: 2.19-1
Severity: normal
Depending on the endian of the system, the macros le64toh(), be64toh(), htole64(), htobe64(), etc. could not return a 64-bit type. This can lead to issues ranging from compilation errors to runtime crashes.
Here is a simple example:
#include <endian.h>
#include <stdio.h>
int main(void)
{
printf("%u\n", (unsigned)sizeof(htobe64(1)));
return 0;
}
On a little endian system this will print 8 while on a big endian system it will print 4. The reason is that on a big endian system the printf line expands to:
printf("%u\n", (unsigned)sizeof((1)));
This can cause many different types of errors (e.g. when passing arguments to a varargs function).
The simplest solution is to change the macros in endian.h to cast the result to the expected type. For example change this:
#define htobe64(x) (x)
to this:
#define htobe64(x) (uint64_t)(x)
I'm going to create a patch for this.
-- System Information:
Debian Release: jessie/sid
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: mips (mips64)
Kernel: Linux 3.2.0-4-5kc-malta
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages libc6-dev depends on:
ii libc-dev-bin 2.19-1
ii libc6 2.19-1
ii linux-libc-dev 3.14.4-1
Versions of packages libc6-dev recommends:
ii gcc [c-compiler] 4:4.8.2-4
ii gcc-4.8 [c-compiler] 4.8.3-2
Versions of packages libc6-dev suggests:
pn glibc-doc <none>
ii manpages-dev 3.65-1
-- no debconf information
Reply to: