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

[PATCH 1/3] make_absolute_path: return the input path if it points to our buffer

From
Carlos Martín Nieto <cmn@elego.de>
Date
Mar 16, 2011, 16:06 UTC
Message-ID
<1300291579-25852-2-git-send-email-cmn@elego.de>
In-Reply-To
<1300291579-25852-1-git-send-email-cmn@elego.de>

Some codepaths call make_absolute_path with its own return value as input. In such a cases, return the path immediately.

This fixes a valgrind-discovered error, whereby we tried to copy a string onto itself.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
 abspath.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/abspath.c b/abspath.c
index 91ca00f..ff14068 100644
--- a/abspath.c
+++ b/abspath.c
@@ -24,6 +24,10 @@ const char *make_absolute_path(const char *path)
 	char *last_elem = NULL;
 	struct stat st;
 
+	/* We've already done it */
+	if (path == buf || path == next_buf)
+		return path;
+
 	if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
 		die ("Too long path: %.*s", 60, path);
 
-- 
1.7.4.1
Previous: Carlos Martín NietoNext: Junio C Hamano
Message 2 of 10 in “Rename make_*_path with clearer names”
  1. 0/3 Rename make_*_path with clearer namesCarlos Martín Nieto, Mar 16, 2011
  2. 1/3 make_absolute_path: return the input path if it points to our bufferCarlos Martín Nieto, Mar 16, 2011
  3. Junio C HamanoMar 16, 2011
  4. 2/3 Name make_*_path functions more accuratelyCarlos Martín Nieto, Mar 16, 2011
  5. Brian GernhardtMar 16, 2011
  6. Carlos Martín NietoMar 16, 2011
  7. 3/3 Use the new {real,absolute}_path function namesCarlos Martín Nieto, Mar 16, 2011
  8. Erik Faye-LundMar 16, 2011
  9. Carlos Martín NietoMar 16, 2011
  10. 3/3 Name make_*_path functions more accuratelyCarlos Martín Nieto, Mar 16, 2011

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.