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

Re: [PATCH] merge-file: correctly find files when called in subdir

From
Thomas Rast <trast@student.ethz.ch>
Date
Oct 17, 2010, 10:39 UTC
Message-ID
<201010171239.13990.trast@student.ethz.ch>
In-Reply-To
<20101017011111.GA26656@burratino>
Jonathan Nieder wrote:
Show 27 quoted lines
> Bert Wesarg wrote:
> > On Sat, Oct 16, 2010 at 13:33, Thomas Rast <trast@student.ethz.ch> wrote:
> 
> >> --- a/builtin/merge-file.c
> >> +++ b/builtin/merge-file.c
> >> @@ -65,10 +66,18 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
> [...]
> >> +               if (prefix)
> >> +                       name = prefix_filename(prefix, prefixlen, argv[i]);
> >> +               else
> >> +                       name = argv[i];
> >
> > I think you can safe this condition, if you set prefixlen to 0.
> 
> I'm not so sure.  On Windows, prefix_filename() starts with
> 
> 	char *p;
> 	/* don't add prefix to absolute paths, but still replace '\' by '/' */
> 	if (is_absolute_path(arg))
> 		pfx_len = 0;
> 	else
> 		memcpy(path, pfx, pfx_len);
> 
> and memcpy() has undefined behavior when pfx is NULL (even with
> pfx_len of 0; see WG14/N1256: 7.21.1 "String function conventions").
> Even if the win32api memcpy does the right thing with NULL pfx, I
> cannot trust GCC when they are given that kind of license. :)
Hmmh.

I was ready to say "you're right" to Bert's suggestion. So maybe, for the sake of foolproof-ness, we should do something like the patch below?

diff --git i/setup.c w/setup.c
index a3b76de..7c8906d 100644
--- i/setup.c
+++ w/setup.c
@@ -55,7 +55,7 @@
 	/* don't add prefix to absolute paths, but still replace '\' by '/' */
 	if (is_absolute_path(arg))
 		pfx_len = 0;
-	else
+	else if (pfx && *pfx)
 		memcpy(path, pfx, pfx_len);
 	strcpy(path + pfx_len, arg);
 	for (p = path + pfx_len; *p; p++)
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Jonathan NiederNext: Jonathan Nieder
Message 4 of 10 in “merge-file: correctly find files when called in subdir”
  1. merge-file: correctly find files when called in subdirThomas Rast, Oct 16, 2010
  2. Bert WesargOct 16, 2010
  3. Jonathan NiederOct 17, 2010
  4. Thomas RastOct 17, 2010
  5. Jonathan NiederOct 17, 2010
  6. 1/2 prefix_filename(): safely handle the case where pfx_len=0Thomas Rast, Oct 17, 2010
  7. 2/2 merge-file: correctly find files when called in subdirThomas Rast, Oct 17, 2010
  8. Jonathan NiederOct 17, 2010
  9. Johannes SixtOct 18, 2010
  10. Jonathan NiederOct 17, 2010

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.