Subject: Re: [PATCH v9 4/6] notes.c: introduce '--separator=<paragraph-break>' option

From: Junio C Hamano <[email-masked]>
Date: Fri, 28 Apr 2023 13:44:10 -0700

Teng Long <[email-masked]> writes:

> +static char *separator = "\n";

The only two ways this pointer gains a non-NULL value are with this
initialization and parsing the command line "--separator=<value>"
option with OPT_STRING().  Neither of them allocate new storage but
points an existing string that we do not "own" (and cannot free)
with the pointer.  So it probably is safer to make it a pointer to a
const string, i.e.

	static const char *separator = "\n";

> @@ -213,65 +229,96 @@ static void write_note_data(struct note_data *d, struct object_id *oid)
>  	}
>  }
>  
> +static void insert_separator(struct strbuf *message, size_t pos)
> +{
> +	if (separator[strlen(separator) - 1] == '\n')
> +		strbuf_addstr(message, separator);
> +	else
> +		strbuf_insertf(message, pos, "%s%s", separator, "\n");
> +}
> +
> +static void concat_messages(struct note_data *d)
> +{
> +	struct strbuf msg = STRBUF_INIT;
> +
> +	size_t i;
> +	for (i = 0; i < d->msg_nr ; i++) {

Wrong placement of the blank line that separates the declaration and
the first statement.