Subject: Re: [PATCH 4/5] apply: error message in `record_ws_error()`

From: Junio C Hamano <[email-masked]>
Date: Mon, 26 Aug 2024 17:44:39 -0700

Rubén Justo <[email-masked]> writes:

> It does not make sense to construct an error message if we're not
> going to use it, especially when the process involves memory
> allocations that need to be freed immediately.
>
> If we know in advance that we won't use the message, not getting it
> slightly reduces the workload and simplifies the code a bit.

Makes sense.

> Do it.

No need to say this when the above two paragraphs are clear enough,
like in this patch.

>
> Signed-off-by: Rubén Justo <[email-masked]>
> ---
>  apply.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/apply.c b/apply.c
> index e1b4d14dba..e6df8b6ab4 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -1642,8 +1642,6 @@ static void record_ws_error(struct apply_state *state,
>  			    int len,
>  			    int linenr)
>  {
> -	char *err;
> -
>  	if (!result)
>  		return;
>  
> @@ -1652,11 +1650,12 @@ static void record_ws_error(struct apply_state *state,
>  	    state->squelch_whitespace_errors < state->whitespace_error)
>  		return;
>  
> -	err = whitespace_error_string(result);
> -	if (state->apply_verbosity > verbosity_silent)
> +	if (state->apply_verbosity > verbosity_silent) {
> +		char *err = whitespace_error_string(result);
>  		fprintf(stderr, "%s:%d: %s.\n%.*s\n",
>  			state->patch_input_file, linenr, err, len, line);
> -	free(err);
> +		free(err);
> +	}
>  }
>  
>  static void check_whitespace(struct apply_state *state,