From c4e1e96032df3247a4a5f3243c55a51c723d3ae1 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sat, 30 Dec 2017 22:01:13 +0200 Subject: divesite.c: use union in create_divesite_uuid() The return produces a warning about "strict-aliasing rules". Use a union to fit the hash and the uint32_t into the same block of memory, which obeys the GCC strict-aliasing rules. Signed-off-by: Lubomir I. Ivanov --- core/divesite.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'core/divesite.c') diff --git a/core/divesite.c b/core/divesite.c index e4ba71abb..18efead7e 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -189,14 +189,17 @@ uint32_t create_divesite_uuid(const char *name, timestamp_t divetime) { if (name == NULL) name =""; - unsigned char hash[20]; + union { + unsigned char hash[20]; + uint32_t i; + } u; SHA_CTX ctx; SHA1_Init(&ctx); SHA1_Update(&ctx, &divetime, sizeof(timestamp_t)); SHA1_Update(&ctx, name, strlen(name)); - SHA1_Final(hash, &ctx); + SHA1_Final(u.hash, &ctx); // now return the first 32 of the 160 bit hash - return *(uint32_t *)hash; + return u.i; } /* allocate a new site and add it to the table */ -- cgit v1.2.3-70-g09d2