Fix type-punning issues
In these two places we are casting part of our unsigned char sha1 array into an unsigned int, which violates GCCs strict-aliasing rules (and probably other compilers). Signed-off-by: Dan McGee <dpmcgee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dan McGee committed
May 11, 2009 at 20:17 UTC
b867d324ceb7e5c4f14a04c6b55d69498812d24b
2 files changed
+5
-2
decorate.c
+3
-1
@@ -8,7 +8,9 @@
8
9
static unsigned int hash_obj(const struct object *obj, unsigned int n)
10
{
11
- unsigned int hash = *(unsigned int *)obj->sha1;
11
+ unsigned int hash;
12
+
13
+ memcpy(&hash, obj->sha1, sizeof(unsigned int));
14
return hash % n;
15
}
16
object.c
+2
-1
@@ -45,7 +45,8 @@ int type_from_string(const char *str)
45
46
static unsigned int hash_obj(struct object *obj, unsigned int n)
47
{
48
- unsigned int hash = *(unsigned int *)obj->sha1;
48
+ unsigned int hash;
49
+ memcpy(&hash, obj->sha1, sizeof(unsigned int));
50
return hash % n;
51
}
52