From b000c59b0c80fc187e5e0e48dc9396cd60576c4e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 10 Jun 2014 17:39:30 -0400 Subject: logmsg_reencode: return const buffer The return value from logmsg_reencode may be either a newly allocated buffer or a pointer to the existing commit->buffer. We would not want the caller to accidentally free() or modify the latter, so let's mark it as const. We can cast away the constness in logmsg_free, but only once we have determined that it is a free-able buffer. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- pretty.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index 3c43db558a..85b0bb3431 100644 --- a/pretty.c +++ b/pretty.c @@ -606,9 +606,9 @@ static char *replace_encoding_header(char *buf, const char *encoding) return strbuf_detach(&tmp, NULL); } -char *logmsg_reencode(const struct commit *commit, - char **commit_encoding, - const char *output_encoding) +const char *logmsg_reencode(const struct commit *commit, + char **commit_encoding, + const char *output_encoding) { static const char *utf8 = "UTF-8"; const char *use_encoding; @@ -687,10 +687,10 @@ char *logmsg_reencode(const struct commit *commit, return out ? out : msg; } -void logmsg_free(char *msg, const struct commit *commit) +void logmsg_free(const char *msg, const struct commit *commit) { if (msg != commit->buffer) - free(msg); + free((void *)msg); } static int mailmap_name(const char **email, size_t *email_len, @@ -796,7 +796,7 @@ struct format_commit_context { struct signature_check signature_check; enum flush_type flush_type; enum trunc_type truncate; - char *message; + const char *message; char *commit_encoding; size_t width, indent1, indent2; int auto_color; @@ -1700,7 +1700,7 @@ void pretty_print_commit(struct pretty_print_context *pp, unsigned long beginning_of_body; int indent = 4; const char *msg; - char *reencoded; + const char *reencoded; const char *encoding; int need_8bit_cte = pp->need_8bit_cte; -- cgit v1.2.3