sctp_darn: fix __u64 format string issues on ppc64 / x86_64
commit398f377fbce6cf7c994d525ab0471cb5bc8d832c
authorDaniel Borkmann <dborkman@redhat.com>
Tue, 22 Jan 2013 15:42:44 +0000 (22 16:42 +0100)
committerDaniel Borkmann <dborkman@redhat.com>
Tue, 22 Jan 2013 15:42:44 +0000 (22 16:42 +0100)
tree8acf639c582c93bffd5fe6aff12ad8856c8d9d6f
parent57911d27b7a5b694aa7ad1ed6b3d8547fcf2d93e
sctp_darn: fix __u64 format string issues on ppc64 / x86_64

On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long.  This causes compiler warnings every time we
print a __u64 value with %PRIu64.

Since we cannot change or define our own u64 type in this case,
because it is within a structiure from the kernel, we just cast it
to uint64_t.

This behaviour can be reduced down to the following program:

  #include <stdio.h>
  #include <inttypes.h>
  #include <netinet/sctp.h>

  int main(void)
  {
          __u64 foo = 1;

          printf("%" PRIu64 "\n", foo);
          printf("%" PRIu64 "\n", (uint64_t) foo);

          printf("__u64:%zu versus uint64_t:%zu\n", sizeof(__u64), sizeof(uint64_t));

          return 0;
  }

On x86_64:

  $ gcc foo.c -Wall -O2
  foo.c: In function ‘main’:
  foo.c:9:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘__u64’ [-Wformat]
  $ ./a.out
  [...]
  __u64:8 versus uint64_t:8

On ppc64:

  $ gcc -Wall -O2 foo.c
  $ ./a.out
  [...]
  __u64:8 versus uint64_t:8

So simply cast it in this case to uint64_t.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
src/apps/sctp_darn.c