mirror of
https://git.zx2c4.com/cgit
synced 2024-11-22 16:38:42 +00:00
shared.c: do not modify const memory
Noticed-by: zhongjj <zhongjj@lemote.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
This commit is contained in:
parent
084ca50972
commit
dc1a8eadd4
14
shared.c
14
shared.c
@ -100,23 +100,15 @@ void *cgit_free_commitinfo(struct commitinfo *info)
|
|||||||
char *trim_end(const char *str, char c)
|
char *trim_end(const char *str, char c)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *s, *t;
|
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
t = (char *)str;
|
len = strlen(str);
|
||||||
len = strlen(t);
|
while(len > 0 && str[len - 1] == c)
|
||||||
while(len > 0 && t[len - 1] == c)
|
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
return xstrndup(str, len);
|
||||||
c = t[len];
|
|
||||||
t[len] = '\0';
|
|
||||||
s = xstrdup(t);
|
|
||||||
t[len] = c;
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strlpart(char *txt, int maxlen)
|
char *strlpart(char *txt, int maxlen)
|
||||||
|
Loading…
Reference in New Issue
Block a user