[patch] shared.c-->trim_end () Segment fault
止语
openlibrary at qq.com
Wed Mar 30 14:56:40 CEST 2011
From: zhongjj <zhongjj at lemote.com>
Date: Wed, 30 Mar 2011 20:15:29 +0800
Subject: [PATCH] to modify the action of changing a char *,or it would cause
Segment fault !
---
shared.c | 9 ++-------
1 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/shared.c b/shared.c
index 7ec2e19..f26477b 100644
--- a/shared.c
+++ b/shared.c
@@ -100,11 +100,9 @@ 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;
+ char *t = xstrdup(str);
len = strlen(t);
while(len > 0 && t[len - 1] == c)
len--;
@@ -112,11 +110,8 @@ char *trim_end(const char *str, char c)
if (len == 0)
return NULL;
- c = t[len];
t[len] = '\0';
- s = xstrdup(t);
- t[len] = c;
- return s;
+ return t;
}
char *strlpart(char *txt, int maxlen)
--
when i used gcc4.5 ,the cgit cgi would Segment fault,so i changed it to above,
------------------
止语
More information about the CGit
mailing list