diff options
author | Thomas Huth <thuth@redhat.com> | 2016-08-08 22:32:36 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-08-16 19:10:55 +1000 |
commit | faa7208616a1774bc7eb520c82c5c739a527017c (patch) | |
tree | 6a06267b4dd4ecaa092414cad6ef91ed5934646f /tools | |
parent | 1bf942576814e1b3dd745b51ad2b8de050ce5e62 (diff) | |
download | SLOF-faa7208616a1774bc7eb520c82c5c739a527017c.zip SLOF-faa7208616a1774bc7eb520c82c5c739a527017c.tar.gz SLOF-faa7208616a1774bc7eb520c82c5c739a527017c.tar.bz2 |
Fix remaining compiler warnings in sloffs.c
With my version of GCC (v4.8.5 - Advance-Toolchain 7.0) there are
currently two warnings when compiling sloffs.c:
sloffs.c: In function 'sloffs_dump':
sloffs.c:437:6: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
printf("%04x", be16_to_cpu(*(uint16_t *)(header->date + 2)));
^
sloffs.c:449:6: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
printf("%04x", be16_to_cpu(*(uint16_t *)(header->mdate + 2)));
^
These can be easily fixed by accessing the memory byte by byte instead of
casting the pointer to (uint16_t *). And while we're at it, let's also
simplify the code a little bit by consolidating the date print code
into a separate function which can be used by the two spots that print
a date.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/sloffs.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/tools/sloffs.c b/tools/sloffs.c index 91a23c3..9a1eace 100644 --- a/tools/sloffs.c +++ b/tools/sloffs.c @@ -405,6 +405,19 @@ sloffs_append(const int file, const char *name, const char *dest) close(out); } +static void print_header_date(void *dptr) +{ + uint8_t *date = dptr; + + if (date[2] || date[3] || date[4] || date[5] || date[6] || date[7]) { + printf("%02x%02x-%02x-%02x %02x:%02x", date[2], date[3], + date[4], date[5], date[6], date[7]); + } else { + printf("N/A"); + } + +} + static void sloffs_dump(const int fd) { @@ -413,7 +426,6 @@ sloffs_dump(const int fd) struct sloffs file; int i; uint64_t crc; - uint64_t *datetmp; uint64_t header_len; header = sloffs_header(fd); @@ -432,28 +444,10 @@ sloffs_dump(const int fd) /* there is a bug in the date position; * it should be at header->date, but it is at (header->date + 2) */ printf(" Build Date : "); - datetmp = (void *)header->date; - if (be64_to_cpu(*datetmp)) { - printf("%04x", be16_to_cpu(*(uint16_t *)(header->date + 2))); - printf("-%02x", *(uint8_t *)(header->date + 4)); - printf("-%02x", *(uint8_t *)(header->date + 5)); - printf(" %02x:", *(uint8_t *)(header->date + 6)); - printf("%02x", *(uint8_t *)(header->date + 7)); - } else { - printf("N/A"); - } + print_header_date(header->date); printf("\n"); printf(" Modify Date : "); - datetmp = (void *)header->mdate; - if (be64_to_cpu(*datetmp)) { - printf("%04x", be16_to_cpu(*(uint16_t *)(header->mdate + 2))); - printf("-%02x", *(uint8_t *)(header->mdate + 4)); - printf("-%02x", *(uint8_t *)(header->mdate + 5)); - printf(" %02x:", *(uint8_t *)(header->mdate + 6)); - printf("%02x", *(uint8_t *)(header->mdate + 7)); - } else { - printf("N/A"); - } + print_header_date(header->mdate); printf("\n"); printf(" Image Length: %ld", be64_to_cpu(header->flashlen)); printf(" (0x%lx) bytes\n", be64_to_cpu(header->flashlen)); |