Skip to content

Commit b867d32

Browse files
toofishesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4b09da commit b867d32

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

decorate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
static unsigned int hash_obj(const struct object *obj, unsigned int n)
1010
{
11-
unsigned int hash = *(unsigned int *)obj->sha1;
11+
unsigned int hash;
12+
13+
memcpy(&hash, obj->sha1, sizeof(unsigned int));
1214
return hash % n;
1315
}
1416

object.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ int type_from_string(const char *str)
4545

4646
static unsigned int hash_obj(struct object *obj, unsigned int n)
4747
{
48-
unsigned int hash = *(unsigned int *)obj->sha1;
48+
unsigned int hash;
49+
memcpy(&hash, obj->sha1, sizeof(unsigned int));
4950
return hash % n;
5051
}
5152

0 commit comments

Comments
 (0)