X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=commit.c;h=754d1b8a0b8282fd3d1d6bd8f6ccb21b407504a5;hb=885b98107547fe3f6d17ca0af0578e040f7600d0;hp=718e568855a37586f99f20bcfafd44cf3aa2b657;hpb=00cec846f157b5363b0967d1e4cba76b44d48e77;p=git.git diff --git a/commit.c b/commit.c index 718e56885..754d1b8a0 100644 --- a/commit.c +++ b/commit.c @@ -654,6 +654,7 @@ static char *get_header(const struct commit *commit, const char *key) static char *replace_encoding_header(char *buf, const char *encoding) { char *encoding_header = strstr(buf, "\nencoding "); + char *header_end = strstr(buf, "\n\n"); char *end_of_encoding_header; int encoding_header_pos; int encoding_header_len; @@ -661,8 +662,10 @@ static char *replace_encoding_header(char *buf, const char *encoding) int need_len; int buflen = strlen(buf) + 1; - if (!encoding_header) - return buf; /* should not happen but be defensive */ + if (!header_end) + header_end = buf + buflen; + if (!encoding_header || encoding_header >= header_end) + return buf; encoding_header++; end_of_encoding_header = strchr(encoding_header, '\n'); if (!end_of_encoding_header) @@ -760,7 +763,7 @@ static void fill_person(struct interp *table, const char *msg, int len) if (msg + start == ep) return; - table[5].value = xstrndup(msg + start, ep - msg + start); + table[5].value = xstrndup(msg + start, ep - (msg + start)); /* parse tz */ for (start = ep - msg + 1; start < len && isspace(msg[start]); start++) @@ -849,19 +852,23 @@ static long format_commit_message(const struct commit *commit, interp_set_entry(table, ITREE_ABBREV, find_unique_abbrev(commit->tree->object.sha1, DEFAULT_ABBREV)); + + parents[1] = 0; for (i = 0, p = commit->parents; p && i < sizeof(parents) - 1; p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ", + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s", sha1_to_hex(p->item->object.sha1)); - interp_set_entry(table, IPARENTS, parents); + interp_set_entry(table, IPARENTS, parents + 1); + + parents[1] = 0; for (i = 0, p = commit->parents; p && i < sizeof(parents) - 1; p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ", + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s", find_unique_abbrev(p->item->object.sha1, DEFAULT_ABBREV)); - interp_set_entry(table, IPARENTS_ABBREV, parents); + interp_set_entry(table, IPARENTS_ABBREV, parents + 1); for (i = 0, state = HEADER; msg[i] && state < BODY; i++) { int eol; @@ -884,7 +891,8 @@ static long format_commit_message(const struct commit *commit, fill_person(table + ICOMMITTER_NAME, msg + i + 10, eol - i - 10); else if (!prefixcmp(msg + i, "encoding ")) - table[IENCODING].value = xstrndup(msg + i, eol - i); + table[IENCODING].value = + xstrndup(msg + i + 9, eol - i - 9); i = eol; } if (msg[i])