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>
This commit is contained in:
parent
070879ca93
commit
2b796360ac
6
object.c
6
object.c
@ -13,17 +13,19 @@ int track_object_refs = 1;
|
|||||||
|
|
||||||
static int hashtable_index(const unsigned char *sha1)
|
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);
|
return (int)(i % obj_allocs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_object(const unsigned char *sha1)
|
static int find_object(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
int i = hashtable_index(sha1);
|
int i;
|
||||||
|
|
||||||
if (!objs)
|
if (!objs)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
i = hashtable_index(sha1);
|
||||||
while (objs[i]) {
|
while (objs[i]) {
|
||||||
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
|
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
|
||||||
return i;
|
return i;
|
||||||
|
Loading…
Reference in New Issue
Block a user