Skip to content

Commit 50546b1

Browse files
sunheehnusgitster
authored andcommitted
Use hashcpy() when copying object names
We invented hashcpy() to keep the abstraction of "object name" behind it. Use it instead of calling memcpy() with hard-coded 20-byte length when moving object names between pieces of memory. Leave ppc/sha1.c as-is, because the function is about the SHA-1 hash algorithm whose output is and will always be 20 bytes. Helped-by: Michael Haggerty <[email protected]> Helped-by: Duy Nguyen <[email protected]> Signed-off-by: Sun He <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ab4ae2 commit 50546b1

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
1919
list->list = xrealloc(list->list,
2020
list->alloc * sizeof(list->list[0]));
2121
}
22-
memcpy(list->list[list->nr].sha1, sha1, 20);
22+
hashcpy(list->list[list->nr].sha1, sha1);
2323
list->list[list->nr].name = xstrdup(name);
2424
list->nr++;
2525
}

grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
16501650
break;
16511651
case GREP_SOURCE_SHA1:
16521652
gs->identifier = xmalloc(20);
1653-
memcpy(gs->identifier, identifier, 20);
1653+
hashcpy(gs->identifier, identifier);
16541654
break;
16551655
case GREP_SOURCE_BUF:
16561656
gs->identifier = NULL;

pack-bitmap-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
530530
header.version = htons(default_version);
531531
header.options = htons(flags | options);
532532
header.entry_count = htonl(writer.selected_nr);
533-
memcpy(header.checksum, writer.pack_checksum, 20);
533+
hashcpy(header.checksum, writer.pack_checksum);
534534

535535
sha1write(f, &header, sizeof(header));
536536
dump_bitmap(f, writer.commits);

reflog-walk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
3232
sizeof(struct reflog_info));
3333
}
3434
item = array->items + array->nr;
35-
memcpy(item->osha1, osha1, 20);
36-
memcpy(item->nsha1, nsha1, 20);
35+
hashcpy(item->osha1, osha1);
36+
hashcpy(item->nsha1, nsha1);
3737
item->email = xstrdup(email);
3838
item->timestamp = timestamp;
3939
item->tz = tz;

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,
12221222
if (ref == NULL)
12231223
return -1;
12241224

1225-
memcpy(sha1, ref->u.value.sha1, 20);
1225+
hashcpy(sha1, ref->u.value.sha1);
12261226
return 0;
12271227
}
12281228

0 commit comments

Comments
 (0)