From 3dd547d851cca5906edc674e127ecaa2b49591b6 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 5 Jun 2013 18:22:26 +0200 X-Upstream-Status: submitted, awaiting merge Subject: [PATCH] libfreefare: resolve compiler warning on breakage of strict aliasing gcc warns: mifare_classic.c:353:45: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] There is another problem with this code: "data", being a 16-byte array, may not be suitably aligned for the other types in the union. This patch resolves this. --- libfreefare/mifare_classic.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c index aaf2d64..1502fe8 100644 --- a/libfreefare/mifare_classic.c +++ b/libfreefare/mifare_classic.c @@ -346,12 +346,10 @@ mifare_classic_init_value (MifareTag tag, const MifareClassicBlockNumber block, int mifare_classic_read_value (MifareTag tag, const MifareClassicBlockNumber block, int32_t *value, MifareClassicBlockNumber *adr) { - MifareClassicBlock data; - if (mifare_classic_read (tag, block, &data) < 0) - return -1; - - union mifare_classic_block b = *((union mifare_classic_block *)(&data)); + union mifare_classic_block b; + if (mifare_classic_read (tag, block, b.data) < 0) + return -1; if ((b.value.value ^ (uint32_t)~b.value.value_) || (b.value.value != b.value.value__)) { errno = EIO; -- 1.8.2