]> granicus.if.org Git - cgit/commitdiff
shared.c: do not modify const memory
authorLars Hjemli <hjemli@gmail.com>
Sun, 22 May 2011 10:45:32 +0000 (12:45 +0200)
committerLars Hjemli <hjemli@gmail.com>
Mon, 23 May 2011 20:58:35 +0000 (22:58 +0200)
Noticed-by: zhongjj <zhongjj@lemote.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
shared.c

index 7ec2e19296e2bfbc7226849163b8bdb05bb56e94..3926b4a1b9bcfe669509c76779e6d85370cb2071 100644 (file)
--- 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)