@matheusbsbs / matheus-bagliano / commits / 2b796360ac
Fork 0

hashtable-based objects: minimum fixups.

Calling hashtable_index from find_object before objs is created would result in division by zero failure. Avoid it. Also the given object name may not be aligned suitably for unsigned int; avoid dereferencing casted pointer. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 11, 2006 at 18:51 UTC 2b796360acbdf3186ab9a5dcb84fe416eda4ffd5
1 file changed +4 -2
object.c
+4 -2
@@ -13,17 +13,19 @@ int track_object_refs = 1;
13
14 static int hashtable_index(const unsigned char *sha1)
15 {
16 - unsigned int i = *(unsigned int *)sha1;
16 + unsigned int i;
17 + memcpy(&i, sha1, sizeof(unsigned int));
18 return (int)(i % obj_allocs);
19 }
20
21 static int find_object(const unsigned char *sha1)
22 {
22 - int i = hashtable_index(sha1);
23 + int i;
24
25 if (!objs)
26 return -1;
27
28 + i = hashtable_index(sha1);
29 while (objs[i]) {
30 if (memcmp(sha1, objs[i]->sha1, 20) == 0)
31 return i;