diff options
author | Pierre Habouzit <madcoder@debian.org> | 2007-09-27 12:58:23 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-29 02:13:33 -0700 |
commit | b315c5c08139c0d3c1e4867a305334e29da01d07 (patch) | |
tree | fd4b122c7dd87e06a642a191b678b426d35e5a5b /builtin-archive.c | |
parent | 690b61f5f13db05aa4ad0efc422bd01aef3c1367 (diff) | |
download | git-b315c5c08139c0d3c1e4867a305334e29da01d07.tar.gz git-b315c5c08139c0d3c1e4867a305334e29da01d07.tar.xz |
strbuf change: be sure ->buf is never ever NULL.
For that purpose, the ->buf is always initialized with a char * buf living
in the strbuf module. It is made a char * so that we can sloppily accept
things that perform: sb->buf[0] = '\0', and because you can't pass "" as an
initializer for ->buf without making gcc unhappy for very good reasons.
strbuf_init/_detach/_grow have been fixed to trust ->alloc and not ->buf
anymore.
as a consequence strbuf_detach is _mandatory_ to detach a buffer, copying
->buf isn't an option anymore, if ->buf is going to escape from the scope,
and eventually be free'd.
API changes:
* strbuf_setlen now always works, so just make strbuf_reset a convenience
macro.
* strbuf_detatch takes a size_t* optional argument (meaning it can be
NULL) to copy the buffer's len, as it was needed for this refactor to
make the code more readable, and working like the callers.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-archive.c')
-rw-r--r-- | builtin-archive.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/builtin-archive.c b/builtin-archive.c index 843a9e37b..04385dea0 100644 --- a/builtin-archive.c +++ b/builtin-archive.c @@ -89,7 +89,7 @@ static void format_subst(const struct commit *commit, struct strbuf fmt; if (src == buf->buf) - to_free = strbuf_detach(buf); + to_free = strbuf_detach(buf, NULL); strbuf_init(&fmt, 0); for (;;) { const char *b, *c; @@ -153,8 +153,7 @@ void *sha1_file_to_archive(const char *path, const unsigned char *sha1, strbuf_attach(&buf, buffer, *sizep, *sizep + 1); convert_to_working_tree(path, buf.buf, buf.len, &buf); convert_to_archive(path, buf.buf, buf.len, &buf, commit); - *sizep = buf.len; - buffer = buf.buf; + buffer = strbuf_detach(&buf, sizep); } return buffer; |