summaryrefslogtreecommitdiff
path: root/mktree.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-06 13:20:05 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-06 23:57:44 -0700
commitb449f4cfc972929b638b90d375b8960c37790618 (patch)
tree4cc9b5425447e4b34966b033a6326ebb50b1e635 /mktree.c
parentb5ef6ac978012475660a36583b2174e9bd8188a5 (diff)
downloadgit-b449f4cfc972929b638b90d375b8960c37790618.tar.gz
Rework strbuf API and semantics.
The gory details are explained in strbuf.h. The change of semantics this patch enforces is that the embeded buffer has always a '\0' character after its last byte, to always make it a C-string. The offs-by-one changes are all related to that very change. A strbuf can be used to store byte arrays, or as an extended string library. The `buf' member can be passed to any C legacy string function, because strbuf operations always ensure there is a terminating \0 at the end of the buffer, not accounted in the `len' field of the structure. A strbuf can be used to generate a string/buffer whose final size is not really known, and then "strbuf_detach" can be used to get the built buffer, and keep the wrapping "strbuf" structure usable for further work again. Other interesting feature: strbuf_grow(sb, size) ensure that there is enough allocated space in `sb' to put `size' new octets of data in the buffer. It helps avoiding reallocating data for nothing when the problem the strbuf helps to solve has a known typical size. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'mktree.c')
-rw-r--r--mktree.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/mktree.c b/mktree.c
index d86dde89d6..86de5eb5f6 100644
--- a/mktree.c
+++ b/mktree.c
@@ -92,7 +92,6 @@ int main(int ac, char **av)
strbuf_init(&sb);
while (1) {
- int len;
char *ptr, *ntr;
unsigned mode;
enum object_type type;
@@ -101,7 +100,6 @@ int main(int ac, char **av)
read_line(&sb, stdin, line_termination);
if (sb.eof)
break;
- len = sb.len;
ptr = sb.buf;
/* Input is non-recursive ls-tree output format
* mode SP type SP sha1 TAB name
@@ -111,7 +109,7 @@ int main(int ac, char **av)
die("input format error: %s", sb.buf);
ptr = ntr + 1; /* type */
ntr = strchr(ptr, ' ');
- if (!ntr || sb.buf + len <= ntr + 41 ||
+ if (!ntr || sb.buf + sb.len <= ntr + 40 ||
ntr[41] != '\t' ||
get_sha1_hex(ntr + 1, sha1))
die("input format error: %s", sb.buf);