]> err.no Git - util-linux/commit
fdisk: fix strict-aliasing bugs
authorKarel Zak <kzak@redhat.com>
Fri, 16 Oct 2009 19:49:33 +0000 (21:49 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Oct 2009 22:18:46 +0000 (00:18 +0200)
commitb2f15782a71fd7d89bed7b3e1f799358779ee828
tree0aa8a6148dc02d102aee300e19709f815902b90c
parent3f8a8dd82f702594f3bb61b15460745e6553ef45
fdisk: fix strict-aliasing bugs

gcc 4.4 produces tons of

  "dereferencing type-punned pointer will break strict-aliasing rules"

warnings for fdisk code where is

  char buffer[BUFSIZ];

  ((struct disklabel *) MBRBuffer)->foo

There are two ways how fix the problem:

  1/ union {
          char buffer[BUFSIZ], struct disklabel label
     } MBRBuffer;

  2/ use allocated buffer, this way seems less invasive.

This patch implements 2/.

Old version:
  $ make -C fdisk | grep -c warning
  236

New version:
  $ make -C fdisk | grep -c warning
  0

About aliasing:
 - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40665
 - http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
 - C99

Signed-off-by: Karel Zak <kzak@redhat.com>
fdisk/fdisk.c
fdisk/fdisk.h
fdisk/fdiskaixlabel.c
fdisk/fdiskmaclabel.c
fdisk/fdisksgilabel.c
fdisk/fdisksunlabel.c