Skip to content

Commit

Permalink
hashtable-based objects: minimum fixups.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 12, 2006
1 parent 070879c commit 2b79636
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2b79636

Please sign in to comment.