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.
This commit is contained in:
Jan Engelhardt 2013-06-05 18:30:39 +02:00 committed by Philippe Teuwen
parent 00e999dd52
commit 089b6006b1

View file

@ -346,13 +346,11 @@ mifare_classic_init_value (MifareTag tag, const MifareClassicBlockNumber block,
int int
mifare_classic_read_value (MifareTag tag, const MifareClassicBlockNumber block, int32_t *value, MifareClassicBlockNumber *adr) mifare_classic_read_value (MifareTag tag, const MifareClassicBlockNumber block, int32_t *value, MifareClassicBlockNumber *adr)
{ {
MifareClassicBlock data; union mifare_classic_block b;
if (mifare_classic_read (tag, block, &data) < 0)
if (mifare_classic_read (tag, block, &b.data) < 0)
return -1; return -1;
union mifare_classic_block b = *((union mifare_classic_block *)(&data));
if ((b.value.value ^ (uint32_t)~b.value.value_) || (b.value.value != b.value.value__)) { if ((b.value.value ^ (uint32_t)~b.value.value_) || (b.value.value != b.value.value__)) {
errno = EIO; errno = EIO;
return -1; return -1;