mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <neolit123@gmail.com>
This commit is contained in:
parent
779292a322
commit
c4e1e96032
1 changed files with 6 additions and 3 deletions
|
@ -189,14 +189,17 @@ uint32_t create_divesite_uuid(const char *name, timestamp_t divetime)
|
||||||
{
|
{
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
name ="";
|
name ="";
|
||||||
unsigned char hash[20];
|
union {
|
||||||
|
unsigned char hash[20];
|
||||||
|
uint32_t i;
|
||||||
|
} u;
|
||||||
SHA_CTX ctx;
|
SHA_CTX ctx;
|
||||||
SHA1_Init(&ctx);
|
SHA1_Init(&ctx);
|
||||||
SHA1_Update(&ctx, &divetime, sizeof(timestamp_t));
|
SHA1_Update(&ctx, &divetime, sizeof(timestamp_t));
|
||||||
SHA1_Update(&ctx, name, strlen(name));
|
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
|
// 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 */
|
/* allocate a new site and add it to the table */
|
||||||
|
|
Loading…
Add table
Reference in a new issue