diff --git a/convert.c b/convert.c index 0d5e909..9100476 100644 --- a/convert.c +++ b/convert.c @@ -84,7 +84,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len, struct strbuf *buf, int action) { struct text_stat stats; - char *dst; + char *dst, *to_free = NULL; if ((action == CRLF_BINARY) || !auto_crlf || !len) return 0; @@ -110,6 +110,10 @@ static int crlf_to_git(const char *path, const char *src, size_t len, return 0; } + /* are we "faking" in place editing ? */ + if (src == buf->buf) + to_free = strbuf_detach(buf, NULL); + strbuf_grow(buf, len); dst = buf->buf; if (action == CRLF_GUESS) { @@ -131,6 +135,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len, } while (--len); } strbuf_setlen(buf, dst - buf->buf); + free(to_free); return 1; } @@ -417,11 +422,15 @@ static int count_ident(const char *cp, unsigned long size) static int ident_to_git(const char *path, const char *src, size_t len, struct strbuf *buf, int ident) { - char *dst, *dollar; + char *dst, *dollar, *to_free = NULL; if (!ident || !count_ident(src, len)) return 0; + /* are we "faking" in place editing ? */ + if (src == buf->buf) + to_free = strbuf_detach(buf, NULL); + strbuf_grow(buf, len); dst = buf->buf; for (;;) { @@ -445,6 +454,7 @@ static int ident_to_git(const char *path, const char *src, size_t len, } memcpy(dst, src, len); strbuf_setlen(buf, dst + len - buf->buf); + free(to_free); return 1; }