about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2011-05-22 12:45:32 +0200
committerLars Hjemli <hjemli@gmail.com>2011-05-23 22:58:35 +0200
commitdc1a8eadd4c063fe6782fa99f9db41c46b85d048 (patch)
treeb946f7378d4a4e846c2b247ee7ed12b3f0784e7e
parenttests: add tests for links with space in path and/or args (diff)
downloadcgit-pink-dc1a8eadd4c063fe6782fa99f9db41c46b85d048.tar.gz
cgit-pink-dc1a8eadd4c063fe6782fa99f9db41c46b85d048.zip
shared.c: do not modify const memory
Noticed-by: zhongjj <zhongjj@lemote.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to '')
-rw-r--r--shared.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/shared.c b/shared.c
index 7ec2e19..3926b4a 100644
--- a/shared.c
+++ b/shared.c
@@ -100,23 +100,15 @@ void *cgit_free_commitinfo(struct commitinfo *info)
 char *trim_end(const char *str, char c)
 {
 	int len;
-	char *s, *t;
 
 	if (str == NULL)
 		return NULL;
-	t = (char *)str;
-	len = strlen(t);
-	while(len > 0 && t[len - 1] == c)
+	len = strlen(str);
+	while(len > 0 && str[len - 1] == c)
 		len--;
-
 	if (len == 0)
 		return NULL;
-
-	c = t[len];
-	t[len] = '\0';
-	s = xstrdup(t);
-	t[len] = c;
-	return s;
+	return xstrndup(str, len);
 }
 
 char *strlpart(char *txt, int maxlen)