Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
hashtable-based objects: minimum fixups.
author
Junio C Hamano
<junkio@cox.net>
Sun, 12 Feb 2006 02:51:19 +0000
(18:51 -0800)
committer
Junio C Hamano
<junkio@cox.net>
Sun, 12 Feb 2006 13:12:39 +0000
(
05:12
-0800)
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>
object.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
070879c
)
diff --git
a/object.c
b/object.c
index 3259862ab2eeeb3adcd52c24c801fd4d4e3212b7..c3616da8131f0cb0a53a8975d15be440c63eebc8 100644
(file)
--- a/
object.c
+++ b/
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);
}
static int find_object(const unsigned char *sha1)
{
return (int)(i % obj_allocs);
}
static int find_object(const unsigned char *sha1)
{
- int i
= hashtable_index(sha1)
;
+ int i;
if (!objs)
return -1;
if (!objs)
return -1;
+ i = hashtable_index(sha1);
while (objs[i]) {
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
return i;
while (objs[i]) {
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
return i;