On 1 October 2015 at 20:16, Lubomir I. Ivanov <[email protected]> wrote:
> On 1 October 2015 at 19:55, Dirk Hohndel <[email protected]> wrote:
>> On Thu, Oct 01, 2015 at 06:32:15PM +0300, Lubomir I. Ivanov wrote:
>>> after seeing a warning about strict-aliasing in:
>>> divesite.c: create_divesite_uuid()
>>>
>>> i think i found a potential problem. the cast at the end of the
>>> function can have different results on big/little endian machines,
>>> while i'm pretty sure we want the same result on both.
>>>
>>> if the first 4 bytes of the SHA1 are:
>>> 01 02 03 04
>>>
>>> we want them serialized in the XML always as:
>>> <site uuid=''01020304" .../>
>>>
>>> on big endian machines that will be the result, while on little endian
>>> the result would be:
>>> <site uuid=''04030201" .../>
>>
>> Since most systems are little endian these days (at least most systems
>> people run Subsurface on) I think we should standardize on the little
>> endian order.
>>
>> So in order to keep things unchanged for everyone on a PC, can you send a
>> modified patch that forces little endian order?
>>
>
> sure thing! :-)
> here is the updated patch.
>


oops, modified the commit message as well in this attachment.

lubomir
--
From 952241fe2e3070bbd707b2826bbbdaa83312b010 Mon Sep 17 00:00:00 2001
From: "Lubomir I. Ivanov" <[email protected]>
Date: Thu, 1 Oct 2015 20:13:20 +0300
Subject: [PATCH 2/2] divesite.c: preserve byte-order in
 create_divesite_uuid()

Casting as *(uint32_t *)hash can have a different meaning
between little and big endian machines, yet the divesite
input properties can be the same.

To preserve the byte order from the generated SHA1 we form
the uint32_t as big-endian ignoring the machine endianness.
From there on, the uint32_t can be serialized to XML exactly
the same on all machines.

Signed-off-by: Lubomir I. Ivanov <[email protected]>
---
 divesite.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/divesite.c b/divesite.c
index e9eed2a..a96f568 100644
--- a/divesite.c
+++ b/divesite.c
@@ -196,7 +196,7 @@ uint32_t create_divesite_uuid(const char *name, timestamp_t divetime)
 	SHA1_Update(&ctx, name, strlen(name));
 	SHA1_Final(hash, &ctx);
 	// now return the first 32 of the 160 bit hash
-	return *(uint32_t *)hash;
+	return hash[0] | hash[1] << 8 | hash[2] << 16 | hash[3] << 24;
 }
 
 /* allocate a new site and add it to the table */
-- 
1.7.11.msysgit.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to