Skip to content

Commit 2b87d3a

Browse files
peffgitster
authored andcommitted
drop strcpy in favor of raw sha1_to_hex
In some cases where we strcpy() the result of sha1_to_hex(), there's no need; the result goes directly into a printf statement, and we can simply pass the return value from sha1_to_hex() directly. When this code was originally written, sha1_to_hex used a single buffer, and it was not safe to use it twice within a single expression. That changed as of dcb3450 (sha1_to_hex() usage cleanup, 2006-05-03), but this code was never updated. History-dug-by: Eric Sunshine <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d59f765 commit 2b87d3a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

http-push.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,6 @@ int main(int argc, char **argv)
18561856

18571857
new_refs = 0;
18581858
for (ref = remote_refs; ref; ref = ref->next) {
1859-
char old_hex[60], *new_hex;
18601859
struct argv_array commit_argv = ARGV_ARRAY_INIT;
18611860

18621861
if (!ref->peer_ref)
@@ -1911,13 +1910,12 @@ int main(int argc, char **argv)
19111910
}
19121911
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
19131912
new_refs++;
1914-
strcpy(old_hex, sha1_to_hex(ref->old_sha1));
1915-
new_hex = sha1_to_hex(ref->new_sha1);
19161913

19171914
fprintf(stderr, "updating '%s'", ref->name);
19181915
if (strcmp(ref->name, ref->peer_ref->name))
19191916
fprintf(stderr, " using '%s'", ref->peer_ref->name);
1920-
fprintf(stderr, "\n from %s\n to %s\n", old_hex, new_hex);
1917+
fprintf(stderr, "\n from %s\n to %s\n",
1918+
sha1_to_hex(ref->old_sha1), sha1_to_hex(ref->new_sha1));
19211919
if (dry_run) {
19221920
if (helper_status)
19231921
printf("ok %s\n", ref->name);

walker.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ void walker_say(struct walker *walker, const char *fmt, const char *hex)
1717

1818
static void report_missing(const struct object *obj)
1919
{
20-
char missing_hex[41];
21-
strcpy(missing_hex, sha1_to_hex(obj->sha1));
2220
fprintf(stderr, "Cannot obtain needed %s %s\n",
23-
obj->type ? typename(obj->type): "object", missing_hex);
21+
obj->type ? typename(obj->type): "object",
22+
sha1_to_hex(obj->sha1));
2423
if (!is_null_sha1(current_commit_sha1))
2524
fprintf(stderr, "while processing commit %s.\n",
2625
sha1_to_hex(current_commit_sha1));

0 commit comments

Comments
 (0)