Thread (1 message) 1 message, 1 author, 2024-08-27

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

From: Junio C Hamano <hidden>
Date: 2024-08-27 00:44:42

Rubén Justo [off-list ref] 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.
quoted hunk
Signed-off-by: Rubén Justo <redacted>
---
 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,
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help