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

Re: [PATCH 4/6] prefix_filename: return newly allocated string

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2017, 18:14 UTC
Message-ID
<xmqqinn2qyyo.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170321012847.yebhpdmk5zrizgmj@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 24 quoted lines
> diff --git a/worktree.c b/worktree.c
> index 42dd3d52b..2520fc65c 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -250,16 +250,19 @@ struct worktree *find_worktree(struct worktree **list,
>  {
>  	struct worktree *wt;
>  	char *path;
> +	char *to_free;
>  
>  	if ((wt = find_worktree_by_suffix(list, arg)))
>  		return wt;
>  
> -	arg = prefix_filename(prefix, arg);
> +	if (prefix)
> +		arg = to_free = prefix_filename(prefix, arg);
>  	path = real_pathdup(arg, 1);
>  	for (; *list; list++)
>  		if (!fspathcmp(path, real_path((*list)->path)))
>  			break;
>  	free(path);
> +	free(to_free);
>  	return *list;
>  }
worktree.c:265:6: error: to_free may be used uninitialized in this function
---
 worktree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/worktree.c b/worktree.c
index 2520fc65cc..bae787cf8d 100644
--- a/worktree.c
+++ b/worktree.c
@@ -250,7 +250,7 @@ struct worktree *find_worktree(struct worktree **list,
 {
 	struct worktree *wt;
 	char *path;
-	char *to_free;
+	char *to_free = NULL;
 
 	if ((wt = find_worktree_by_suffix(list, arg)))
 		return wt;
-- 
2.12.1-382-gc0f9c70589
Previous: Jeff KingNext: Jeff King
Message 6 of 11 in “prefix_filename cleanups”
  1. 0/6 prefix_filename cleanupsJeff King, Mar 21, 2017
  2. 1/6 hash-object: fix buffer reuse with --path in a subdirectoryJeff King, Mar 21, 2017
  3. 2/6 prefix_filename: move docstring to header fileJeff King, Mar 21, 2017
  4. 3/6 prefix_filename: drop length parameterJeff King, Mar 21, 2017
  5. 4/6 prefix_filename: return newly allocated stringJeff King, Mar 21, 2017
  6. Junio C HamanoMar 21, 2017
  7. Jeff KingMar 21, 2017
  8. Jeff KingMar 21, 2017
  9. 5/6 prefix_filename: simplify windows #ifdefJeff King, Mar 21, 2017
  10. 6/6 bundle: use prefix_filename with bundle pathJeff King, Mar 21, 2017
  11. Junio C HamanoMar 21, 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.