@matheusbsbs / matheus-bagliano / commits / a89fccd281
Fork 0

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>

David Rientjes committed Aug 17, 2006 at 11:54 UTC a89fccd28197fa179828c8596791ff16e2268d20
31 files changed +74 -71
builtin-commit-tree.c
+1 -1
@@ -69,7 +69,7 @@ static int new_parent(int idx)
69 int i;
70 unsigned char *sha1 = parent_sha1[idx];
71 for (i = 0; i < idx; i++) {
72 - if (!memcmp(parent_sha1[i], sha1, 20)) {
72 + if (!hashcmp(parent_sha1[i], sha1)) {
73 error("duplicate parent %s ignored", sha1_to_hex(sha1));
74 return 0;
75 }
builtin-diff-stages.c
+1 -1
@@ -46,7 +46,7 @@ static void diff_stages(int stage1, int stage2, const char **pathspec)
46 else if (!two)
47 diff_addremove(&diff_options, '-', ntohl(one->ce_mode),
48 one->sha1, name, NULL);
49 - else if (memcmp(one->sha1, two->sha1, 20) ||
49 + else if (hashcmp(one->sha1, two->sha1) ||
50 (one->ce_mode != two->ce_mode) ||
51 diff_options.find_copies_harder)
52 diff_change(&diff_options,
builtin-diff.c
+1 -1
@@ -69,7 +69,7 @@ static void stuff_change(struct diff_options *opt,
69 struct diff_filespec *one, *two;
70
71 if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&
72 - !memcmp(old_sha1, new_sha1, 20))
72 + !hashcmp(old_sha1, new_sha1))
73 return;
74
75 if (opt->reverse_diff) {
builtin-pack-objects.c
+4 -4
@@ -441,7 +441,7 @@ static int locate_object_entry_hash(const unsigned char *sha1)
441 memcpy(&ui, sha1, sizeof(unsigned int));
442 i = ui % object_ix_hashsz;
443 while (0 < object_ix[i]) {
444 - if (!memcmp(sha1, objects[object_ix[i]-1].sha1, 20))
444 + if (!hashcmp(sha1, objects[object_ix[i] - 1].sha1))
445 return i;
446 if (++i == object_ix_hashsz)
447 i = 0;
@@ -607,7 +607,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
607 */
608 for (neigh = 0; neigh < 8; neigh++) {
609 ent = pbase_tree_cache[my_ix];
610 - if (ent && !memcmp(ent->sha1, sha1, 20)) {
610 + if (ent && !hashcmp(ent->sha1, sha1)) {
611 ent->ref++;
612 return ent;
613 }
@@ -789,7 +789,7 @@ static void add_preferred_base(unsigned char *sha1)
789 return;
790
791 for (it = pbase_tree; it; it = it->next) {
792 - if (!memcmp(it->pcache.sha1, tree_sha1, 20)) {
792 + if (!hashcmp(it->pcache.sha1, tree_sha1)) {
793 free(data);
794 return;
795 }
@@ -931,7 +931,7 @@ static struct object_entry **create_sorted_list(entry_sort_t sort)
931
932 static int sha1_sort(const struct object_entry *a, const struct object_entry *b)
933 {
934 - return memcmp(a->sha1, b->sha1, 20);
934 + return hashcmp(a->sha1, b->sha1);
935 }
936
937 static struct object_entry **create_final_object_list(void)
builtin-show-branch.c
+2 -2
@@ -378,7 +378,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1)
378 /* If both heads/foo and tags/foo exists, get_sha1 would
379 * get confused.
380 */
381 - if (get_sha1(refname + ofs, tmp) || memcmp(tmp, sha1, 20))
381 + if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
382 ofs = 5;
383 return append_ref(refname + ofs, sha1);
384 }
@@ -442,7 +442,7 @@ static int rev_is_head(char *head_path, int headlen, char *name,
442 {
443 int namelen;
444 if ((!head_path[0]) ||
445 - (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))
445 + (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
446 return 0;
447 namelen = strlen(name);
448 if ((headlen < namelen) ||
builtin-unpack-objects.c
+2 -2
@@ -136,7 +136,7 @@ static void added_object(unsigned char *sha1, const char *type, void *data, unsi
136 struct delta_info *info;
137
138 while ((info = *p) != NULL) {
139 - if (!memcmp(info->base_sha1, sha1, 20)) {
139 + if (!hashcmp(info->base_sha1, sha1)) {
140 *p = info->next;
141 p = &delta_list;
142 resolve_delta(type, data, size, info->delta, info->size);
@@ -292,7 +292,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
292 unpack_all();
293 SHA1_Update(&ctx, buffer, offset);
294 SHA1_Final(sha1, &ctx);
295 - if (memcmp(fill(20), sha1, 20))
295 + if (hashcmp(fill(20), sha1))
296 die("final sha1 did not match");
297 use(20);
298
builtin-update-index.c
+2 -2
@@ -378,7 +378,7 @@ static int unresolve_one(const char *path)
378 ret = -1;
379 goto free_return;
380 }
381 - if (!memcmp(ce_2->sha1, ce_3->sha1, 20) &&
381 + if (!hashcmp(ce_2->sha1, ce_3->sha1) &&
382 ce_2->ce_mode == ce_3->ce_mode) {
383 fprintf(stderr, "%s: identical in both, skipping.\n",
384 path);
@@ -460,7 +460,7 @@ static int do_reupdate(int ac, const char **av,
460 old = read_one_ent(NULL, head_sha1,
461 ce->name, ce_namelen(ce), 0);
462 if (old && ce->ce_mode == old->ce_mode &&
463 - !memcmp(ce->sha1, old->sha1, 20)) {
463 + !hashcmp(ce->sha1, old->sha1)) {
464 free(old);
465 continue; /* unchanged */
466 }
cache.h
+4
@@ -214,6 +214,10 @@ static inline int is_null_sha1(const unsigned char *sha1)
214 {
215 return !memcmp(sha1, null_sha1, 20);
216 }
217 +static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
218 +{
219 + return memcmp(sha1, sha2, 20);
220 +}
221
222 int git_mkstemp(char *path, size_t n, const char *template);
223
combine-diff.c
+2 -2
@@ -688,8 +688,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
688 for (i = 0; i < num_parent; i++) {
689 int j;
690 for (j = 0; j < i; j++) {
691 - if (!memcmp(elem->parent[i].sha1,
692 - elem->parent[j].sha1, 20)) {
691 + if (!hashcmp(elem->parent[i].sha1,
692 + elem->parent[j].sha1)) {
693 reuse_combine_diff(sline, cnt, i, j);
694 break;
695 }
commit.c
+1 -1
@@ -123,7 +123,7 @@ static int commit_graft_pos(const unsigned char *sha1)
123 while (lo < hi) {
124 int mi = (lo + hi) / 2;
125 struct commit_graft *graft = commit_graft[mi];
126 - int cmp = memcmp(sha1, graft->sha1, 20);
126 + int cmp = hashcmp(sha1, graft->sha1);
127 if (!cmp)
128 return mi;
129 if (cmp < 0)
convert-objects.c
+1 -1
@@ -39,7 +39,7 @@ static struct entry *lookup_entry(unsigned char *sha1)
39 while (low < high) {
40 int next = (low + high) / 2;
41 struct entry *n = convert[next];
42 - int cmp = memcmp(sha1, n->old_sha1, 20);
42 + int cmp = hashcmp(sha1, n->old_sha1);
43 if (!cmp)
44 return n;
45 if (cmp < 0) {
diff-lib.c
+1 -1
@@ -215,7 +215,7 @@ static int show_modified(struct rev_info *revs,
215 }
216
217 oldmode = old->ce_mode;
218 - if (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&
218 + if (mode == oldmode && !hashcmp(sha1, old->sha1) &&
219 !revs->diffopt.find_copies_harder)
220 return 0;
221
diff.c
+5 -5
@@ -1140,7 +1140,7 @@ static int work_tree_matches(const char *name, const unsigned char *sha1)
1140 if ((lstat(name, &st) < 0) ||
1141 !S_ISREG(st.st_mode) || /* careful! */
1142 ce_match_stat(ce, &st, 0) ||
1143 - memcmp(sha1, ce->sha1, 20))
1143 + hashcmp(sha1, ce->sha1))
1144 return 0;
1145 /* we return 1 only when we can stat, it is a regular file,
1146 * stat information matches, and sha1 recorded in the cache
@@ -1168,7 +1168,7 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
1168 while (last > first) {
1169 int cmp, next = (last + first) >> 1;
1170 e = sha1_size_cache[next];
1171 - cmp = memcmp(e->sha1, sha1, 20);
1171 + cmp = hashcmp(e->sha1, sha1);
1172 if (!cmp)
1173 return e;
1174 if (cmp < 0) {
@@ -1579,7 +1579,7 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
1579 ;
1580 }
1581
1582 - if (memcmp(one->sha1, two->sha1, 20)) {
1582 + if (hashcmp(one->sha1, two->sha1)) {
1583 int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
1584
1585 len += snprintf(msg + len, sizeof(msg) - len,
@@ -2098,7 +2098,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
2098 * dealing with a change.
2099 */
2100 if (one->sha1_valid && two->sha1_valid &&
2101 - !memcmp(one->sha1, two->sha1, sizeof(one->sha1)))
2101 + !hashcmp(one->sha1, two->sha1))
2102 return 1; /* no change */
2103 if (!one->sha1_valid && !two->sha1_valid)
2104 return 1; /* both look at the same file on the filesystem. */
@@ -2237,7 +2237,7 @@ static void diff_resolve_rename_copy(void)
2237 if (!p->status)
2238 p->status = DIFF_STATUS_RENAMED;
2239 }
2240 - else if (memcmp(p->one->sha1, p->two->sha1, 20) ||
2240 + else if (hashcmp(p->one->sha1, p->two->sha1) ||
2241 p->one->mode != p->two->mode)
2242 p->status = DIFF_STATUS_MODIFIED;
2243 else {
diffcore-break.c
+1 -1
@@ -56,7 +56,7 @@ static int should_break(struct diff_filespec *src,
56 return 0; /* leave symlink rename alone */
57
58 if (src->sha1_valid && dst->sha1_valid &&
59 - !memcmp(src->sha1, dst->sha1, 20))
59 + !hashcmp(src->sha1, dst->sha1))
60 return 0; /* they are the same */
61
62 if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))
diffcore-rename.c
+1 -1
@@ -101,7 +101,7 @@ static int is_exact_match(struct diff_filespec *src,
101 int contents_too)
102 {
103 if (src->sha1_valid && dst->sha1_valid &&
104 - !memcmp(src->sha1, dst->sha1, 20))
104 + !hashcmp(src->sha1, dst->sha1))
105 return 1;
106 if (!contents_too)
107 return 0;
dump-cache-tree.c
+1 -1
@@ -33,7 +33,7 @@ static int dump_cache_tree(struct cache_tree *it,
33 }
34 else {
35 dump_one(it, pfx, "");
36 - if (memcmp(it->sha1, ref->sha1, 20) ||
36 + if (hashcmp(it->sha1, ref->sha1) ||
37 ref->entry_count != it->entry_count ||
38 ref->subtree_nr != it->subtree_nr) {
39 dump_one(ref, pfx, "#(ref) ");
http-fetch.c
+3 -3
@@ -301,7 +301,7 @@ static void finish_object_request(struct object_request *obj_req)
301 unlink(obj_req->tmpfile);
302 return;
303 }
304 - if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
304 + if (hashcmp(obj_req->sha1, obj_req->real_sha1)) {
305 unlink(obj_req->tmpfile);
306 return;
307 }
@@ -1070,7 +1070,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
1070 int ret = 0;
1071 struct object_request *obj_req = object_queue_head;
1072
1073 - while (obj_req != NULL && memcmp(obj_req->sha1, sha1, 20))
1073 + while (obj_req != NULL && hashcmp(obj_req->sha1, sha1))
1074 obj_req = obj_req->next;
1075 if (obj_req == NULL)
1076 return error("Couldn't find request for %s in the queue", hex);
@@ -1109,7 +1109,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
1109 } else if (obj_req->zret != Z_STREAM_END) {
1110 corrupt_object_found++;
1111 ret = error("File %s (%s) corrupt", hex, obj_req->url);
1112 - } else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
1112 + } else if (hashcmp(obj_req->sha1, obj_req->real_sha1)) {
1113 ret = error("File %s has bad hash", hex);
1114 } else if (obj_req->rename < 0) {
1115 ret = error("unable to write sha1 filename %s",
http-push.c
+2 -2
@@ -745,7 +745,7 @@ static void finish_request(struct transfer_request *request)
745 SHA1_Final(request->real_sha1, &request->c);
746 if (request->zret != Z_STREAM_END) {
747 unlink(request->tmpfile);
748 - } else if (memcmp(request->obj->sha1, request->real_sha1, 20)) {
748 + } else if (hashcmp(request->obj->sha1, request->real_sha1)) {
749 unlink(request->tmpfile);
750 } else {
751 request->rename =
@@ -2416,7 +2416,7 @@ int main(int argc, char **argv)
2416
2417 if (!ref->peer_ref)
2418 continue;
2419 - if (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {
2419 + if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
2420 if (push_verbosely || 1)
2421 fprintf(stderr, "'%s': up-to-date\n", ref->name);
2422 continue;
index-pack.c
+6 -6
@@ -82,7 +82,7 @@ static void parse_pack_header(void)
82 SHA1_Init(&ctx);
83 SHA1_Update(&ctx, pack_base, pack_size - 20);
84 SHA1_Final(sha1, &ctx);
85 - if (memcmp(sha1, pack_base + pack_size - 20, 20))
85 + if (hashcmp(sha1, pack_base + pack_size - 20))
86 die("packfile '%s' SHA1 mismatch", pack_name);
87 }
88
@@ -189,7 +189,7 @@ static int find_delta(const unsigned char *base_sha1)
189 struct delta_entry *delta = &deltas[next];
190 int cmp;
191
192 - cmp = memcmp(base_sha1, delta->base_sha1, 20);
192 + cmp = hashcmp(base_sha1, delta->base_sha1);
193 if (!cmp)
194 return next;
195 if (cmp < 0) {
@@ -210,9 +210,9 @@ static int find_deltas_based_on_sha1(const unsigned char *base_sha1,
210
211 if (first < 0)
212 return -1;
213 - while (first > 0 && !memcmp(deltas[first-1].base_sha1, base_sha1, 20))
213 + while (first > 0 && !hashcmp(deltas[first - 1].base_sha1, base_sha1))
214 --first;
215 - while (last < end && !memcmp(deltas[last+1].base_sha1, base_sha1, 20))
215 + while (last < end && !hashcmp(deltas[last + 1].base_sha1, base_sha1))
216 ++last;
217 *first_index = first;
218 *last_index = last;
@@ -278,7 +278,7 @@ static int compare_delta_entry(const void *a, const void *b)
278 {
279 const struct delta_entry *delta_a = a;
280 const struct delta_entry *delta_b = b;
281 - return memcmp(delta_a->base_sha1, delta_b->base_sha1, 20);
281 + return hashcmp(delta_a->base_sha1, delta_b->base_sha1);
282 }
283
284 static void parse_pack_objects(void)
@@ -350,7 +350,7 @@ static int sha1_compare(const void *_a, const void *_b)
350 {
351 struct object_entry *a = *(struct object_entry **)_a;
352 struct object_entry *b = *(struct object_entry **)_b;
353 - return memcmp(a->sha1, b->sha1, 20);
353 + return hashcmp(a->sha1, b->sha1);
354 }
355
356 static void write_index_file(const char *index_name, unsigned char *sha1)
merge-tree.c
+1 -1
@@ -152,7 +152,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
152 {
153 return a->sha1 &&
154 b->sha1 &&
155 - !memcmp(a->sha1, b->sha1, 20) &&
155 + !hashcmp(a->sha1, b->sha1) &&
156 a->mode == b->mode;
157 }
158
object.c
+1 -1
@@ -58,7 +58,7 @@ struct object *lookup_object(const unsigned char *sha1)
58
59 i = hashtable_index(sha1);
60 while ((obj = obj_hash[i]) != NULL) {
61 - if (!memcmp(sha1, obj->sha1, 20))
61 + if (!hashcmp(sha1, obj->sha1))
62 break;
63 i++;
64 if (i == obj_hash_size)
pack-check.c
+3 -3
@@ -29,10 +29,10 @@ static int verify_packfile(struct packed_git *p)
29 pack_base = p->pack_base;
30 SHA1_Update(&ctx, pack_base, pack_size - 20);
31 SHA1_Final(sha1, &ctx);
32 - if (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))
32 + if (hashcmp(sha1, (unsigned char *)pack_base + pack_size - 20))
33 return error("Packfile %s SHA1 mismatch with itself",
34 p->pack_name);
35 - if (memcmp(sha1, (char *) index_base + index_size - 40, 20))
35 + if (hashcmp(sha1, (unsigned char *)index_base + index_size - 40))
36 return error("Packfile %s SHA1 mismatch with idx",
37 p->pack_name);
38
@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose)
135 SHA1_Init(&ctx);
136 SHA1_Update(&ctx, index_base, index_size - 20);
137 SHA1_Final(sha1, &ctx);
138 - if (memcmp(sha1, (char *) index_base + index_size - 20, 20))
138 + if (hashcmp(sha1, (unsigned char *)index_base + index_size - 20))
139 ret = error("Packfile index for %s SHA1 mismatch",
140 p->pack_name);
141
pack-redundant.c
+7 -7
@@ -139,7 +139,7 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
139
140 l = (hint == NULL) ? list->front : hint;
141 while (l) {
142 - int cmp = memcmp(l->sha1, sha1, 20);
142 + int cmp = hashcmp(l->sha1, sha1);
143 if (cmp > 0) { /* we insert before this entry */
144 return llist_insert(list, prev, sha1);
145 }
@@ -162,7 +162,7 @@ redo_from_start:
162 l = (hint == NULL) ? list->front : hint;
163 prev = NULL;
164 while (l) {
165 - int cmp = memcmp(l->sha1, sha1, 20);
165 + int cmp = hashcmp(l->sha1, sha1);
166 if (cmp > 0) /* not in list, since sorted */
167 return prev;
168 if(!cmp) { /* found */
@@ -256,7 +256,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
256 while (p1_off <= p1->pack->index_size - 3 * 20 &&
257 p2_off <= p2->pack->index_size - 3 * 20)
258 {
259 - int cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);
259 + int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
260 /* cmp ~ p1 - p2 */
261 if (cmp == 0) {
262 p1_hint = llist_sorted_remove(p1->unique_objects,
@@ -351,16 +351,16 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
351 {
352 size_t ret = 0;
353 int p1_off, p2_off;
354 - char *p1_base, *p2_base;
354 + unsigned char *p1_base, *p2_base;
355
356 p1_off = p2_off = 256 * 4 + 4;
357 - p1_base = (char *)p1->index_base;
358 - p2_base = (char *)p2->index_base;
357 + p1_base = (unsigned char *)p1->index_base;
358 + p2_base = (unsigned char *)p2->index_base;
359
360 while (p1_off <= p1->index_size - 3 * 20 &&
361 p2_off <= p2->index_size - 3 * 20)
362 {
363 - int cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);
363 + int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
364 /* cmp ~ p1 - p2 */
365 if (cmp == 0) {
366 ret++;
read-cache.c
+2 -2
@@ -60,7 +60,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
60 if (fd >= 0) {
61 unsigned char sha1[20];
62 if (!index_fd(sha1, fd, st, 0, NULL))
63 - match = memcmp(sha1, ce->sha1, 20);
63 + match = hashcmp(sha1, ce->sha1);
64 /* index_fd() closed the file descriptor already */
65 }
66 return match;
@@ -744,7 +744,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
744 SHA1_Init(&c);
745 SHA1_Update(&c, hdr, size - 20);
746 SHA1_Final(sha1, &c);
747 - if (memcmp(sha1, (char *) hdr + size - 20, 20))
747 + if (hashcmp(sha1, (unsigned char *)hdr + size - 20))
748 return error("bad index file sha1 signature");
749 return 0;
750 }
refs.c
+4 -4
@@ -281,7 +281,7 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
281 unlock_ref(lock);
282 return NULL;
283 }
284 - if (memcmp(lock->old_sha1, old_sha1, 20)) {
284 + if (hashcmp(lock->old_sha1, old_sha1)) {
285 error("Ref %s is at %s but expected %s", lock->ref_file,
286 sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
287 unlock_ref(lock);
@@ -411,7 +411,7 @@ int write_ref_sha1(struct ref_lock *lock,
411
412 if (!lock)
413 return -1;
414 - if (!lock->force_write && !memcmp(lock->old_sha1, sha1, 20)) {
414 + if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
415 unlock_ref(lock);
416 return 0;
417 }
@@ -475,7 +475,7 @@ int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1)
475 die("Log %s is corrupt.", logfile);
476 if (get_sha1_hex(rec + 41, sha1))
477 die("Log %s is corrupt.", logfile);
478 - if (memcmp(logged_sha1, sha1, 20)) {
478 + if (hashcmp(logged_sha1, sha1)) {
479 tz = strtoul(tz_c, NULL, 10);
480 fprintf(stderr,
481 "warning: Log %s has gap after %s.\n",
@@ -489,7 +489,7 @@ int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1)
489 else {
490 if (get_sha1_hex(rec + 41, logged_sha1))
491 die("Log %s is corrupt.", logfile);
492 - if (memcmp(logged_sha1, sha1, 20)) {
492 + if (hashcmp(logged_sha1, sha1)) {
493 tz = strtoul(tz_c, NULL, 10);
494 fprintf(stderr,
495 "warning: Log %s unexpectedly ended on %s.\n",
send-pack.c
+1 -1
@@ -265,7 +265,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
265 char old_hex[60], *new_hex;
266 if (!ref->peer_ref)
267 continue;
268 - if (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {
268 + if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
269 if (verbose)
270 fprintf(stderr, "'%s': up-to-date\n", ref->name);
271 continue;
sha1_file.c
+8 -8
@@ -485,10 +485,10 @@ int use_packed_git(struct packed_git *p)
485 /* Check if the pack file matches with the index file.
486 * this is cheap.
487 */
488 - if (memcmp((char*)(p->index_base) + p->index_size - 40,
489 - (char *) p->pack_base + p->pack_size - 20,
490 - 20)) {
491 -
488 + if (hashcmp((unsigned char *)(p->index_base) +
489 + p->index_size - 40,
490 + (unsigned char *)p->pack_base +
491 + p->pack_size - 20)) {
492 die("packfile %s does not match index.", p->pack_name);
493 }
494 }
@@ -643,7 +643,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long siz
643 SHA1_Update(&c, header, 1+sprintf(header, "%s %lu", type, size));
644 SHA1_Update(&c, map, size);
645 SHA1_Final(real_sha1, &c);
646 - return memcmp(sha1, real_sha1, 20) ? -1 : 0;
646 + return hashcmp(sha1, real_sha1) ? -1 : 0;
647 }
648
649 void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
@@ -941,7 +941,7 @@ int check_reuse_pack_delta(struct packed_git *p, unsigned long offset,
941 ptr = unpack_object_header(p, ptr, kindp, sizep);
942 if (*kindp != OBJ_DELTA)
943 goto done;
944 - memcpy(base, (char *) p->pack_base + ptr, 20);
944 + memcpy(base, (unsigned char *) p->pack_base + ptr, 20);
945 status = 0;
946 done:
947 unuse_packed_git(p);
@@ -1206,7 +1206,7 @@ int find_pack_entry_one(const unsigned char *sha1,
1206
1207 do {
1208 int mi = (lo + hi) / 2;
1209 - int cmp = memcmp((char *) index + (24 * mi) + 4, sha1, 20);
1209 + int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);
1210 if (!cmp) {
1211 e->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));
1212 memcpy(e->sha1, sha1, 20);
@@ -1715,7 +1715,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
1715 unlink(tmpfile);
1716 return error("File %s corrupted", sha1_to_hex(sha1));
1717 }
1718 - if (memcmp(sha1, real_sha1, 20)) {
1718 + if (hashcmp(sha1, real_sha1)) {
1719 unlink(tmpfile);
1720 return error("File %s has bad hash", sha1_to_hex(sha1));
1721 }
sha1_name.c
+3 -3
@@ -84,7 +84,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
84 int cmp;
85
86 nth_packed_object_sha1(p, mid, now);
87 - cmp = memcmp(match, now, 20);
87 + cmp = hashcmp(match, now);
88 if (!cmp) {
89 first = mid;
90 break;
@@ -106,7 +106,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
106 memcpy(found_sha1, now, 20);
107 found++;
108 }
109 - else if (memcmp(found_sha1, now, 20)) {
109 + else if (hashcmp(found_sha1, now)) {
110 found = 2;
111 break;
112 }
@@ -144,7 +144,7 @@ static int find_unique_short_object(int len, char *canonical,
144 return 0;
145 }
146 /* Both have unique ones -- do they match? */
147 - if (memcmp(packed_sha1, unpacked_sha1, 20))
147 + if (hashcmp(packed_sha1, unpacked_sha1))
148 return SHORT_NAME_AMBIGUOUS;
149 memcpy(sha1, packed_sha1, 20);
150 return 0;
ssh-fetch.c
+1 -1
@@ -67,7 +67,7 @@ int fetch(unsigned char *sha1)
67 signed char remote;
68 struct object_list *temp;
69
70 - if (memcmp(sha1, in_transit->item->sha1, 20)) {
70 + if (hashcmp(sha1, in_transit->item->sha1)) {
71 /* we must have already fetched it to clean the queue */
72 return has_sha1_file(sha1) ? 0 : -1;
73 }
tree-diff.c
+1 -2
@@ -39,8 +39,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
39 show_entry(opt, "+", t2, base);
40 return 1;
41 }
42 - if (!opt->find_copies_harder &&
43 - !memcmp(sha1, sha2, 20) && mode1 == mode2)
42 + if (!opt->find_copies_harder && !hashcmp(sha1, sha2) && mode1 == mode2)
43 return 0;
44
45 /*
unpack-trees.c
+1 -1
@@ -417,7 +417,7 @@ static int same(struct cache_entry *a, struct cache_entry *b)
417 if (!a && !b)
418 return 1;
419 return a->ce_mode == b->ce_mode &&
420 - !memcmp(a->sha1, b->sha1, 20);
420 + !hashcmp(a->sha1, b->sha1);
421 }
422
423