From: Dan McGee Date: Tue, 12 May 2009 01:17:38 +0000 (-0500) Subject: Fix type-punning issues X-Git-Tag: v1.6.3.2~33 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b867d324ceb7e5c4f14a04c6b55d69498812d24b;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/decorate.c b/decorate.c index 82d9e221e..e6fd8a744 100644 --- a/decorate.c +++ b/decorate.c @@ -8,7 +8,9 @@ static unsigned int hash_obj(const struct object *obj, unsigned int n) { - unsigned int hash = *(unsigned int *)obj->sha1; + unsigned int hash; + + memcpy(&hash, obj->sha1, sizeof(unsigned int)); return hash % n; } diff --git a/object.c b/object.c index 7e6a92c88..e1feef9c3 100644 --- a/object.c +++ b/object.c @@ -45,7 +45,8 @@ int type_from_string(const char *str) static unsigned int hash_obj(struct object *obj, unsigned int n) { - unsigned int hash = *(unsigned int *)obj->sha1; + unsigned int hash; + memcpy(&hash, obj->sha1, sizeof(unsigned int)); return hash % n; }