Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
Introduces global inline: hashcmp(const unsigned char *sha1, const unsigned char *sha2) Uses memcmp for comparison and returns the result based on the length of the hash name (a future runtime decision). Acked-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
d4baf9eaf4
commit
a89fccd281
12
index-pack.c
12
index-pack.c
@ -82,7 +82,7 @@ static void parse_pack_header(void)
|
||||
SHA1_Init(&ctx);
|
||||
SHA1_Update(&ctx, pack_base, pack_size - 20);
|
||||
SHA1_Final(sha1, &ctx);
|
||||
if (memcmp(sha1, pack_base + pack_size - 20, 20))
|
||||
if (hashcmp(sha1, pack_base + pack_size - 20))
|
||||
die("packfile '%s' SHA1 mismatch", pack_name);
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ static int find_delta(const unsigned char *base_sha1)
|
||||
struct delta_entry *delta = &deltas[next];
|
||||
int cmp;
|
||||
|
||||
cmp = memcmp(base_sha1, delta->base_sha1, 20);
|
||||
cmp = hashcmp(base_sha1, delta->base_sha1);
|
||||
if (!cmp)
|
||||
return next;
|
||||
if (cmp < 0) {
|
||||
@ -210,9 +210,9 @@ static int find_deltas_based_on_sha1(const unsigned char *base_sha1,
|
||||
|
||||
if (first < 0)
|
||||
return -1;
|
||||
while (first > 0 && !memcmp(deltas[first-1].base_sha1, base_sha1, 20))
|
||||
while (first > 0 && !hashcmp(deltas[first - 1].base_sha1, base_sha1))
|
||||
--first;
|
||||
while (last < end && !memcmp(deltas[last+1].base_sha1, base_sha1, 20))
|
||||
while (last < end && !hashcmp(deltas[last + 1].base_sha1, base_sha1))
|
||||
++last;
|
||||
*first_index = first;
|
||||
*last_index = last;
|
||||
@ -278,7 +278,7 @@ static int compare_delta_entry(const void *a, const void *b)
|
||||
{
|
||||
const struct delta_entry *delta_a = a;
|
||||
const struct delta_entry *delta_b = b;
|
||||
return memcmp(delta_a->base_sha1, delta_b->base_sha1, 20);
|
||||
return hashcmp(delta_a->base_sha1, delta_b->base_sha1);
|
||||
}
|
||||
|
||||
static void parse_pack_objects(void)
|
||||
@ -350,7 +350,7 @@ static int sha1_compare(const void *_a, const void *_b)
|
||||
{
|
||||
struct object_entry *a = *(struct object_entry **)_a;
|
||||
struct object_entry *b = *(struct object_entry **)_b;
|
||||
return memcmp(a->sha1, b->sha1, 20);
|
||||
return hashcmp(a->sha1, b->sha1);
|
||||
}
|
||||
|
||||
static void write_index_file(const char *index_name, unsigned char *sha1)
|
||||
|
Reference in New Issue
Block a user