diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-07-19 23:22:22 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-19 23:22:22 +0300 |
commit | 96e08010ee5b9d1dbfbcc8561fa69f972a415a38 (patch) | |
tree | 03768d6b32e30959c8c587fcd73ca3c1da8ae275 | |
parent | f5236a776f31de2654bca9001aa74ef9fe0819d8 (diff) | |
parent | 54307ea7c3ced760ee375483a786ec7180798aed (diff) |
Merge branch 'jk/printf-format'
Code clean-up to avoid using a variable string that compilers may
feel untrustable as printf-style format given to write_file()
helper function.
* jk/printf-format:
commit.c: remove print_commit_list()
avoid using sha1_to_hex output as printf format
walker: let walker_say take arbitrary formats
-rw-r--r-- | bisect.c | 5 | ||||
-rw-r--r-- | builtin/worktree.c | 2 | ||||
-rw-r--r-- | commit.c | 10 | ||||
-rw-r--r-- | commit.h | 4 | ||||
-rw-r--r-- | walker.c | 10 | ||||
-rw-r--r-- | walker.h | 3 |
6 files changed, 14 insertions, 20 deletions
@@ -646,7 +646,10 @@ static void exit_if_skipped_commits(struct commit_list *tried, printf("There are only 'skip'ped commits left to test.\n" "The first %s commit could be any of:\n", term_bad); - print_commit_list(tried, "%s\n", "%s\n"); + + for ( ; tried; tried = tried->next) + printf("%s\n", oid_to_hex(&tried->item->object.oid)); + if (bad) printf("%s\n", oid_to_hex(bad)); printf(_("We cannot bisect more!\n")); diff --git a/builtin/worktree.c b/builtin/worktree.c index e866844685..cce555cbbc 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -262,7 +262,7 @@ static int add_worktree(const char *path, const char *refname, */ strbuf_reset(&sb); strbuf_addf(&sb, "%s/HEAD", sb_repo.buf); - write_file(sb.buf, sha1_to_hex(null_sha1)); + write_file(sb.buf, "%s", sha1_to_hex(null_sha1)); strbuf_reset(&sb); strbuf_addf(&sb, "%s/commondir", sb_repo.buf); write_file(sb.buf, "../.."); @@ -1622,16 +1622,6 @@ struct commit_list **commit_list_append(struct commit *commit, return &new->next; } -void print_commit_list(struct commit_list *list, - const char *format_cur, - const char *format_last) -{ - for ( ; list; list = list->next) { - const char *format = list->next ? format_cur : format_last; - printf(format, oid_to_hex(&list->item->object.oid)); - } -} - const char *find_commit_header(const char *msg, const char *key, size_t *out_len) { int key_len = strlen(key); @@ -377,10 +377,6 @@ extern int parse_signed_commit(const struct commit *commit, struct strbuf *message, struct strbuf *signature); extern int remove_signature(struct strbuf *buf); -extern void print_commit_list(struct commit_list *list, - const char *format_cur, - const char *format_last); - /* * Check the signature of the given commit. The result of the check is stored * in sig->check_result, 'G' for a good signature, 'U' for a good signature @@ -9,10 +9,14 @@ static unsigned char current_commit_sha1[20]; -void walker_say(struct walker *walker, const char *fmt, const char *hex) +void walker_say(struct walker *walker, const char *fmt, ...) { - if (walker->get_verbosely) - fprintf(stderr, fmt, hex); + if (walker->get_verbosely) { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + } } static void report_missing(const struct object *obj) @@ -19,7 +19,8 @@ struct walker { }; /* Report what we got under get_verbosely */ -void walker_say(struct walker *walker, const char *, const char *); +__attribute__((format (printf, 2, 3))) +void walker_say(struct walker *walker, const char *fmt, ...); /* Load pull targets from stdin */ int walker_targets_stdin(char ***target, const char ***write_ref); |