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

[PATCH] Use PATH_MAX rather than a hardwired constant maximum length.

From
koreth@midwinter.com <koreth@midwinter.com>
Date
Apr 26, 2007, 09:12 UTC
Message-ID
<20070426091254.GA23586@midwinter.com>
In-Reply-To
<46306A29.4010608@midwinter.com>
Signed-off-by: Steven Grimm <koreth@midwinter.com>
---

Is the +1 really needed? The existing code is doing this in other places but I'm not sure it's necessary since we're also doing sizeof(buffer)-1 in the getcwd() call. I figured it was best to be consistent with the existing code, e.g. setup_git_directory_gently().

 setup.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/setup.c b/setup.c
index a45ea83..84d3c4a 100644
--- a/setup.c
+++ b/setup.c
@@ -175,11 +175,11 @@ static int inside_git_dir = -1;
 int is_inside_git_dir(void)
 {
 	if (inside_git_dir < 0) {
-		char buffer[1024];
+		char buffer[PATH_MAX+1];
 
 		if (is_bare_repository())
 			return (inside_git_dir = 1);
-		if (getcwd(buffer, sizeof(buffer))) {
+		if (getcwd(buffer, sizeof(buffer)-1)) {
 			const char *git_dir = get_git_dir(), *cwd = buffer;
 			while (*git_dir && *git_dir == *cwd) {
 				git_dir++;
-- 
1.5.2.rc0.35.gf41c8
Previous: Steven GrimmNext: Alex Riesen
Message 4 of 6 in “Change git-rev-parse --show-cdup to output an absolute path”
  1. Change git-rev-parse --show-cdup to output an absolute pathkoreth@midwinter.com, Apr 25, 2007
  2. Alex RiesenApr 26, 2007
  3. Steven GrimmApr 26, 2007
  4. Use PATH_MAX rather than a hardwired constant maximum length.koreth@midwinter.com, Apr 26, 2007
  5. Alex RiesenApr 26, 2007
  6. Alex RiesenApr 26, 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.