summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-02-11 18:51:19 -0800
committerJunio C Hamano <junkio@cox.net>2006-02-12 05:12:39 -0800
commit2b796360acbdf3186ab9a5dcb84fe416eda4ffd5 (patch)
tree69299088522856a61ccab7d07eabf3f6c6ce4bd6
parent070879ca93a7d358086f4c8aff4553493dcb9210 (diff)
downloadgit-2b796360acbdf3186ab9a5dcb84fe416eda4ffd5.tar.gz
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>
-rw-r--r--object.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/object.c b/object.c
index 3259862ab2..c3616da813 100644
--- a/object.c
+++ b/object.c
@@ -13,17 +13,19 @@ int track_object_refs = 1;
static int hashtable_index(const unsigned char *sha1)
{
- unsigned int i = *(unsigned int *)sha1;
+ unsigned int i;
+ memcpy(&i, sha1, sizeof(unsigned int));
return (int)(i % obj_allocs);
}
static int find_object(const unsigned char *sha1)
{
- int i = hashtable_index(sha1);
+ int i;
if (!objs)
return -1;
+ i = hashtable_index(sha1);
while (objs[i]) {
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
return i;