cherry-pick: format help message as strbuf
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>
Jeff King committed
Feb 11, 2010 at 16:07 UTC
08565bdb4b5d1da597ed8b90d1a23729f7c006d0
1 file changed
+4
-4
builtin-revert.c
+4
-4
@@ -200,23 +200,23 @@ static void set_author_ident_env(const char *message)
200
201
static char *help_msg(const unsigned char *sha1)
202
{
203
- static char helpbuf[1024];
203
+ struct strbuf helpbuf = STRBUF_INIT;
204
char *msg = getenv("GIT_CHERRY_PICK_HELP");
205
206
if (msg)
207
return msg;
208
209
- strcpy(helpbuf, " After resolving the conflicts,\n"
209
+ strbuf_addstr(&helpbuf, " After resolving the conflicts,\n"
210
"mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n"
211
"and commit the result.");
212
213
if (action == CHERRY_PICK) {
214
- sprintf(helpbuf + strlen(helpbuf),
214
+ strbuf_addf(&helpbuf,
215
" When committing, use the option '-c %s'\n"
216
"to retain authorship and message.",
217
find_unique_abbrev(sha1, DEFAULT_ABBREV));
218
}
219
- return helpbuf;
219
+ return strbuf_detach(&helpbuf, NULL);
220
}
221
222
static struct tree *empty_tree(void)