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

[PATCH 1/3] builtin-branch: use strbuf in delete_branches()

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Nov 17, 2008, 20:48 UTC
Message-ID
<b3716161b2a3d508ec4306623c5c8889d9367e1d.1226954771.git.vmiklos@frugalware.org>
In-Reply-To
<cover.1226954771.git.vmiklos@frugalware.org>

In case the length of branch name is greather then PATH_MAX-7, we write to unallocated memory otherwise.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 builtin-branch.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index 2b3613f..b9149b7 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -97,7 +97,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 	unsigned char sha1[20];
 	char *name = NULL;
 	const char *fmt, *remote;
-	char section[PATH_MAX];
 	int i;
 	int ret = 0;
 
@@ -165,11 +164,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 			       argv[i]);
 			ret = 1;
 		} else {
+			struct strbuf buf = STRBUF_INIT;
 			printf("Deleted %sbranch %s.\n", remote, argv[i]);
-			snprintf(section, sizeof(section), "branch.%s",
-				 argv[i]);
-			if (git_config_rename_section(section, NULL) < 0)
+			strbuf_addf(&buf, "branch.%s", argv[i]);
+			if (git_config_rename_section(buf.buf, NULL) < 0)
 				warning("Update of config-file failed");
+			strbuf_release(&buf);
 		}
 	}
 
-- 
1.6.0.2
Previous: Miklos VajnaNext: Miklos Vajna
Message 2 of 7 in “builtin-branch: use strbuf”
  1. 0/3 builtin-branch: use strbufMiklos Vajna, Nov 17, 2008
  2. 1/3 builtin-branch: use strbuf in delete_branches()Miklos Vajna, Nov 17, 2008
  3. 2/3 builtin-branch: use strbuf in fill_tracking_info()Miklos Vajna, Nov 17, 2008
  4. 3/3 builtin-branch: use strbuf in rename_branch()Miklos Vajna, Nov 17, 2008
  5. Junio C HamanoNov 18, 2008
  6. Johannes SchindelinNov 19, 2008
  7. Lars HjemliNov 19, 2008

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.