git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fixup! bisect--helper: `bisect_next_check` & bisect_voc shell function in C

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2017, 19:14 UTC
Message-ID
<xmqqinodewdr.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<74dfcffe-274c-7045-420a-95612394d66b@web.de>
René Scharfe <l.s.r@web.de> writes:
> Initializing to NULL is still the correct thing to do, of course --
> together with removing the conditionals (or at least the negations).

So, let's give Pranit a concrete "here is what we want to see squashed in", while you guys discuss peculiarity with various platforms and their system headers, which admittedly is a more interesting tangent ;-)

There are early returns with "goto finish" even before _syn variables are first assigned to, so they would need to be initialized to NULL. The other two get their initial values right at the beginning, so they are OK.

 builtin/bisect--helper.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 8cd6527bd1..6949e8e5ca 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -280,7 +280,7 @@ static int bisect_next_check(const struct bisect_terms *terms,
 	int missing_good = 1, missing_bad = 1, retval = 0;
 	char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
 	char *good_glob = xstrfmt("%s-*", terms->term_good);
-	char *bad_syn, *good_syn;
+	char *bad_syn = NULL, *good_syn = NULL;
 
 	if (ref_exists(bad_ref))
 		missing_bad = 0;
@@ -341,14 +341,10 @@ static int bisect_next_check(const struct bisect_terms *terms,
 	}
 	goto finish;
 finish:
-	if (!bad_ref)
-		free(bad_ref);
-	if (!good_glob)
-		free(good_glob);
-	if (!bad_syn)
-		free(bad_syn);
-	if (!good_syn)
-		free(good_syn);
+	free(bad_ref);
+	free(good_glob);
+	free(bad_syn);
+	free(good_syn);
 	return retval;
 }
 
Previous: René ScharfeNext: Pranit Bauva
Message 6 of 8 in “fixup! bisect--helper: `bisect_next_check` & bisect_voc shell function in C”
  1. fixup! bisect--helper: `bisect_next_check` & bisect_voc shell function in CJohannes Schindelin, Feb 10, 2017
  2. Pranit BauvaFeb 10, 2017
  3. René ScharfeFeb 10, 2017
  4. Johannes SchindelinFeb 13, 2017
  5. René ScharfeFeb 13, 2017
  6. Junio C HamanoFeb 13, 2017
  7. Pranit BauvaFeb 13, 2017
  8. Junio C HamanoFeb 19, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.