Subject: [PATCH] Off-by-one error in get_path_prefix(), found by Valgrind

From: Pavel Roskin <[email-masked]>
Date: Wed, 07 Jun 2006 13:01:40 -0400

From: Pavel Roskin <[email-masked]>

Signed-off-by: Pavel Roskin <[email-masked]>
---

 builtin-tar-tree.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 5f740cf..05da1f2 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -166,8 +166,8 @@ static unsigned int ustar_header_chksum(
 static int get_path_prefix(const struct strbuf *path, int maxlen)
 {
 	int i = path->len;
-	if (i > maxlen)
-		i = maxlen;
+	if (i >= maxlen)
+		i = maxlen - 1;
 	while (i > 0 && path->buf[i] != '/')
 		i--;
 	return i;