author | Lars Hjemli <hjemli@gmail.com> | 2011-05-22 10:45:32 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2011-05-23 20:58:35 (UTC) |
commit | dc1a8eadd4c063fe6782fa99f9db41c46b85d048 (patch) (unidiff) | |
tree | b946f7378d4a4e846c2b247ee7ed12b3f0784e7e | |
parent | 084ca50972b4be120eba8d22ce585766ae315c36 (diff) | |
download | cgit-dc1a8eadd4c063fe6782fa99f9db41c46b85d048.zip cgit-dc1a8eadd4c063fe6782fa99f9db41c46b85d048.tar.gz cgit-dc1a8eadd4c063fe6782fa99f9db41c46b85d048.tar.bz2 |
shared.c: do not modify const memory
Noticed-by: zhongjj <zhongjj@lemote.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | shared.c | 14 |
1 files changed, 3 insertions, 11 deletions
@@ -91,41 +91,33 @@ void *cgit_free_commitinfo(struct commitinfo *info) | |||
91 | free(info->committer); | 91 | free(info->committer); |
92 | free(info->committer_email); | 92 | free(info->committer_email); |
93 | free(info->subject); | 93 | free(info->subject); |
94 | free(info->msg); | 94 | free(info->msg); |
95 | free(info->msg_encoding); | 95 | free(info->msg_encoding); |
96 | free(info); | 96 | free(info); |
97 | return NULL; | 97 | return NULL; |
98 | } | 98 | } |
99 | 99 | ||
100 | char *trim_end(const char *str, char c) | 100 | char *trim_end(const char *str, char c) |
101 | { | 101 | { |
102 | int len; | 102 | int len; |
103 | char *s, *t; | ||
104 | 103 | ||
105 | if (str == NULL) | 104 | if (str == NULL) |
106 | return NULL; | 105 | return NULL; |
107 | t = (char *)str; | 106 | len = strlen(str); |
108 | len = strlen(t); | 107 | while(len > 0 && str[len - 1] == c) |
109 | while(len > 0 && t[len - 1] == c) | ||
110 | len--; | 108 | len--; |
111 | |||
112 | if (len == 0) | 109 | if (len == 0) |
113 | return NULL; | 110 | return NULL; |
114 | 111 | return xstrndup(str, len); | |
115 | c = t[len]; | ||
116 | t[len] = '\0'; | ||
117 | s = xstrdup(t); | ||
118 | t[len] = c; | ||
119 | return s; | ||
120 | } | 112 | } |
121 | 113 | ||
122 | char *strlpart(char *txt, int maxlen) | 114 | char *strlpart(char *txt, int maxlen) |
123 | { | 115 | { |
124 | char *result; | 116 | char *result; |
125 | 117 | ||
126 | if (!txt) | 118 | if (!txt) |
127 | return txt; | 119 | return txt; |
128 | 120 | ||
129 | if (strlen(txt) <= maxlen) | 121 | if (strlen(txt) <= maxlen) |
130 | return txt; | 122 | return txt; |
131 | result = xmalloc(maxlen + 1); | 123 | result = xmalloc(maxlen + 1); |