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

Re: [PATCH] Fix set_work_tree on cygwin

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 2, 2007, 21:36 UTC
Message-ID
<Pine.LNX.4.64.0708022230070.14781@racer.site>
In-Reply-To
<7vwswdtz98.fsf@assigned-by-dhcp.cox.net>
Hi,
On Thu, 2 Aug 2007, Junio C Hamano wrote:
Show 36 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > Hi,
> >
> > On Thu, 2 Aug 2007, Alex Riesen wrote:
> >
> >> Johannes Schindelin, Thu, Aug 02, 2007 17:38:37 +0200:
> >> 
> >> > On Thu, 2 Aug 2007, Alex Riesen wrote:
> >> > 
> >> > >@@ -209,7 +209,8 @@ const char *set_work_tree(const char *dir)
> >> > >        len = strlen(dir);
> >> > >        if (len > postfix_len && !strcmp(dir + len - postfix_len,
> >> > >                                "/" DEFAULT_GIT_DIR_ENVIRONMENT)) {
> >> > >-                       strncpy(dir_buffer, dir, len - postfix_len);
> >> > >+               strncpy(dir_buffer, dir, len - postfix_len);
> >> > >+               dir_buffer[len - postfix_len] = '\0';
> >> > >
> >> > >                /* are we inside the default work tree? */
> >> > >                rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer);
> >> > 
> >> > Darn, darn, darn.  strncpy does _not_ NUL terminate.  I keep forgetting 
> >> > that.
> >> > 
> >> > Better use strlcpy()?
> >> 
> >> Of course, but it just should not be needed at all: static supposed to
> >> be zeroed.
> >
> > Certainly.  But reality outweighs theory, and so I Ack either your patch 
> > or replacing it by strlcpy().
> 
> Static is supposed to be zeroed and also is supposed to retain
> the value from the previous call.  I am guessing from the change
> to make "rel" to non-static that this function is called twice
> perhaps?

Apparently (but I would feel safer with strlcpy() anyway). git-read-tree is the first and only offender which comes up in the test suite:

-- snipsnap -- [PATCH] read-tree: remove unnecessary call to setup_git_directory()

read-tree is already marked with RUN_SETUP in git.c, so there is no need to call setup_git_directory() a second time.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-read-tree.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 41f8110..a3b17a3 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -97,7 +97,6 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 	memset(&opts, 0, sizeof(opts));
 	opts.head_idx = -1;
 
-	setup_git_directory();
 	git_config(git_default_config);
 
 	newfd = hold_locked_index(&lock_file, 1);
-- 
1.5.3.rc3.121.g7f37
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 9 in “Fix set_work_tree on cygwin”
  1. Fix set_work_tree on cygwinAlex Riesen, Aug 2, 2007
  2. Johannes SchindelinAug 2, 2007
  3. Alex RiesenAug 2, 2007
  4. Johannes SchindelinAug 2, 2007
  5. Junio C HamanoAug 2, 2007
  6. Johannes SchindelinAug 2, 2007
  7. Junio C HamanoAug 2, 2007
  8. Allow setup_work_tree() to be called several timesJohannes Schindelin, Aug 2, 2007
  9. Fix unterminated string copy in set_work_treeAlex Riesen, Aug 2, 2007

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.