Skip to content

Commit

Permalink
Fix type-punning issues
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dan McGee authored and Junio C Hamano committed May 17, 2009
1 parent e4b09da commit b867d32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion decorate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b867d32

Please sign in to comment.