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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Do it.

Signed-off-by: Rubén Justo <rjusto@xxxxxxxxx>
---
 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,
-- 
2.46.0.353.g385c909849




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux