Skip to content

Commit

Permalink
cherry-pick: format help message as strbuf
Browse files Browse the repository at this point in the history
This gets rid of the fixed-size buffer and an unchecked
sprintf. That sprintf is actually OK as the only
variable-sized thing put in it is an abbreviated sha1, which
is bounded at 40 characters. However, the next patch will
change that to something unbounded.

Note that this function now returns an allocated buffer
instead of a static one; however, it doesn't matter as the
only caller exits immediately.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 12, 2010
1 parent dd9314c commit 08565bd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions builtin-revert.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,23 @@ static void set_author_ident_env(const char *message)

static char *help_msg(const unsigned char *sha1)
{
static char helpbuf[1024];
struct strbuf helpbuf = STRBUF_INIT;
char *msg = getenv("GIT_CHERRY_PICK_HELP");

if (msg)
return msg;

strcpy(helpbuf, " After resolving the conflicts,\n"
strbuf_addstr(&helpbuf, " After resolving the conflicts,\n"
"mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n"
"and commit the result.");

if (action == CHERRY_PICK) {
sprintf(helpbuf + strlen(helpbuf),
strbuf_addf(&helpbuf,
" When committing, use the option '-c %s'\n"
"to retain authorship and message.",
find_unique_abbrev(sha1, DEFAULT_ABBREV));
}
return helpbuf;
return strbuf_detach(&helpbuf, NULL);
}

static struct tree *empty_tree(void)
Expand Down

0 comments on commit 08565bd

Please sign in to comment.