From dc1a8eadd4c063fe6782fa99f9db41c46b85d048 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 22 May 2011 12:45:32 +0200 Subject: shared.c: do not modify const memory Noticed-by: zhongjj Signed-off-by: Lars Hjemli --- shared.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'shared.c') 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) -- cgit v1.2.3-70-g09d2