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>
This commit is contained in:
Dan McGee 2009-05-11 20:17:38 -05:00 committed by Junio C Hamano
parent e4b09dad9f
commit b867d324ce
2 changed files with 5 additions and 2 deletions

View File

@ -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;
}

View File

@ -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;
}