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) (side-by-side diff) | |
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
@@ -101,21 +101,13 @@ 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); } |