Bug 859427 - be64toh returns unsigned long long int regardless of word length
Summary: be64toh returns unsigned long long int regardless of word length
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: rawhide
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Jeff Law
QA Contact: Fedora Extras Quality Assurance
Depends On:
Blocks: 859428
TreeView+ depends on / blocked
Reported: 2012-09-21 14:14 UTC by Matthew Booth
Modified: 2016-11-24 15:38 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 859428 (view as bug list)
Last Closed: 2012-12-06 08:22:09 UTC

Attachments (Terms of Use)

Description Matthew Booth 2012-09-21 14:14:36 UTC
Description of problem:
I have some code something like this:

uint64_t be;
printf(PRIu64, be64toh(be));

This compiles on F17, but not on F18 and rawhide. The error is:

ldm.c:1079:5: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'long long unsigned int' [-Werror=format]

In F17, __bswap_64 is defined as:

# if __WORDSIZE == 64
#  define __bswap_64(x) \
     (__extension__                                                           \
      ({ register unsigned long __v, __x = (x);                               \
# else
#  define __bswap_64(x) \
     (__extension__                                                           \
      ({ union { __extension__ unsigned long long int __ll;                   \

However, on F18 and rawhide it becomes:

# if __GNUC_PREREQ (4, 2)
static __inline unsigned long long int
__bswap_64 (unsigned long long int __bsx)
  return __builtin_bswap64 (__bsx);
# elif __WORDSIZE == 64
<as above>

This means that on in F18 and rawhide, it returns unsigned long long int regardless of word length, which isn't the case on F17, causing my code to not compile.

Version-Release number of selected component (if applicable):

Comment 1 Jeff Law 2012-09-25 20:19:15 UTC
Unfortunately, you're going to need to fix your code as I don't see this changing.

By going to a uniform "unsigned long long" return value it makes it easier to generally avoid warnings in packages which are compiled for multiple architectures with varying wordsizes.

Comment 2 Matthew Booth 2012-09-26 11:37:09 UTC
Reopening. I didn't mark this as a regression lightly :) I'm interested to know what a 'fix' would look like in this case.

The man page for be64toh() defines the function as:

       uint64_t be64toh(uint64_t big_endian_64bits);

If I cast the return of be64toh() to uint64_t in the above case, the code compiles fine. However, this is a nonsense as that's the defined return type! Rather than returning unsigned long long, the code could instead return it's documented uint64_t, whose definition is wordsize-dependent.

Comment 3 Siddhesh Poyarekar 2012-12-06 08:22:09 UTC
This was fixed in rawhide with a rebase since upstream got this patch in October:


Note You need to log in before you can comment on or make changes to this bug.