From faa7208616a1774bc7eb520c82c5c739a527017c Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 8 Aug 2016 22:32:36 +0200 Subject: 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 Signed-off-by: Alexey Kardashevskiy --- tools/sloffs.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'tools') 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)); -- cgit v1.1