Thread (104 messages) flat view 104 messages, 5 authors, 2016-06-15
STALE3751d

[PATCH 33/67] read_branches_file: replace strcpy with xstrdup

From: Jeff King <hidden>
Date: 2016-06-15 23:06:33
Subsystem: the rest · Maintainer: Linus Torvalds

This code is exactly replicating strdup, so let's just use
that. It's shorter, and eliminates some confusion (such as
whether "p - s" is really enough to hold the result; it is,
because we write NULs as we shrink "p").

Signed-off-by: Jeff King <redacted>
---
 remote.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/remote.c b/remote.c
index 5ab0f7f..1b69751 100644
--- a/remote.c
+++ b/remote.c
@@ -297,7 +297,6 @@ static void read_branches_file(struct remote *remote)
 	int n = 1000;
 	FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
 	char *s, *p;
-	int len;
 
 	if (!f)
 		return;
@@ -313,9 +312,7 @@ static void read_branches_file(struct remote *remote)
 	p = s + strlen(s);
 	while (isspace(p[-1]))
 		*--p = 0;
-	len = p - s;
-	p = xmalloc(len + 1);
-	strcpy(p, s);
+	p = xstrdup(s);
 
 	/*
 	 * The branches file would have URL and optionally
-- 
2.6.0.rc2.408.ga2926b9
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help