Off-by-one error in get_path_prefix(), found by Valgrind
authorRene Scharfe <rene.scharfe@lsrfire.ath.cx>
Wed, 7 Jun 2006 18:05:43 +0000 (20:05 +0200)
committerJunio C Hamano <junkio@cox.net>
Wed, 7 Jun 2006 18:49:08 +0000 (11:49 -0700)
[jc: original fix was done by Pavel and this contains improvements
 by Rene.]

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Acked-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-tar-tree.c

index 5f740cf..7663b9b 100644 (file)
@@ -168,8 +168,9 @@ static int get_path_prefix(const struct strbuf *path, int maxlen)
        int i = path->len;
        if (i > maxlen)
                i = maxlen;
-       while (i > 0 && path->buf[i] != '/')
+       do {
                i--;
+       } while (i > 0 && path->buf[i] != '/');
        return i;
 }