]> Pileus Git - ~andy/git/commitdiff
cherry-pick: do not dump core when iconv fails
authorJonathan Nieder <jrnieder@gmail.com>
Sat, 8 May 2010 23:17:29 +0000 (18:17 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 8 May 2010 23:56:21 +0000 (16:56 -0700)
When cherry-picking, usually the new and old commit encodings are both
UTF-8.  Most old iconv implementations do not support this trivial
conversion, so on old platforms, out->message remains NULL, and later
attempts to read it segfault.

Fix this by noticing the input and output encodings match and skipping
the iconv step, like the other reencode_string() call sites already do.
Also stop segfaulting on other iconv failures: if iconv fails for some
other reason, the best we can do is to pass the old message through.

This fixes a regression introduced in v1.7.1-rc0~15^2~2 (revert:
clarify label on conflict hunks, 2010-03-20).

Reported-by: Andreas Krey <a.krey@gmx.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/revert.c

index 778a56eb512edde3aac6c2a4d668cc73ab3d8460..7d68ef714eee5011d82952ca1829016c90827f61 100644 (file)
@@ -109,8 +109,13 @@ static int get_message(const char *raw_message, struct commit_message *out)
                encoding = "UTF-8";
        if (!git_commit_encoding)
                git_commit_encoding = "UTF-8";
-       if ((out->reencoded_message = reencode_string(raw_message,
-                                       git_commit_encoding, encoding)))
+
+       out->reencoded_message = NULL;
+       out->message = raw_message;
+       if (strcmp(encoding, git_commit_encoding))
+               out->reencoded_message = reencode_string(raw_message,
+                                       git_commit_encoding, encoding);
+       if (out->reencoded_message)
                out->message = out->reencoded_message;
 
        abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);