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:
parent
e4b09dad9f
commit
b867d324ce
@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
static unsigned int hash_obj(const struct object *obj, unsigned int n)
|
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;
|
return hash % n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
object.c
3
object.c
@ -45,7 +45,8 @@ int type_from_string(const char *str)
|
|||||||
|
|
||||||
static unsigned int hash_obj(struct object *obj, unsigned int n)
|
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;
|
return hash % n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user