Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1434956820.15674.1.camel@inria.fr>
Date: Mon, 22 Jun 2015 09:07:00 +0200
From: Jens Gustedt <jens.gustedt@...ia.fr>
To: musl@...ts.openwall.com
Cc: Rafał Miłecki <zajec5@...il.com>
Subject: Re: Using __BYTE_ORDER without endian.h

Am Montag, den 22.06.2015, 08:57 +0200 schrieb Rafał Miłecki:
> Hi,
> 
> So far we were using uClibc in OpenWrt and my following code was working fine:
> 
> #include <byteswap.h>
> #include <errno.h>
> #include <stdint.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> 
> #if __BYTE_ORDER == __BIG_ENDIAN
> #define cpu_to_le32(x) bswap_32(x)
> #define le32_to_cpu(x) bswap_32(x)
> #elif __BYTE_ORDER == __LITTLE_ENDIAN
> #define cpu_to_le32(x) (x)
> #define le32_to_cpu(x) (x)
> #else
> #error "Unsupported endianness"
> #endif
> 
> Unfortunately is is *silently* broken with musl. When using musl and
> not including endian.h directly the condition:
> #if __BYTE_ORDER == __BIG_ENDIAN
> is always true.

This is correct behavior. Identifiers that are unknown to the
preprocessor always evaluate to 0 and 0 == 0 is true.

> Could you fix this?
> 
> I expect either:
> 1) __BYTE_ORDER to be always available & set correctly
> 2) Compile error because of __BYTE_ORDER being undefined
> 
> I think such silent miscompilation is sth that has to be avoided.

You should fix your erroneous code by prefixing with something like

#if !defined(__BYTE_ORDER) && !defined(__BIG_ENDIAN)

Jens



-- 
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::





Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.