summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2020-02-20 20:07:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-20 22:43:36 (GMT)
commit6c11c6a124a0175f4d1b94f0fa077ed1c098339b (patch)
treeaebeeb6579a6afb5bad61534e42e53d9064f4d2f /dir.c
parentef07659926f64d70e8cb41025c3d7456eecb962e (diff)
downloadgit-6c11c6a124a0175f4d1b94f0fa077ed1c098339b.zip
git-6c11c6a124a0175f4d1b94f0fa077ed1c098339b.tar.gz
git-6c11c6a124a0175f4d1b94f0fa077ed1c098339b.tar.bz2
sparse-checkout: allow one-character directories in cone mode
In 9e6d3e64 (sparse-checkout: detect short patterns, 2020-01-24), a condition on the minimum length of a cone-mode pattern was introduced. However, this condition was off-by-one. If we have a directory with a single character, say "b", then the command git sparse-checkout set b will correctly add the pattern "/b/" to the sparse-checkout file. When this is interpeted in dir.c, the pattern is "/b" with the PATTERN_FLAG_MUSTBEDIR flag. This string has length two, which satisfies our inclusive inequality (<= 2). The reason for this inequality is that we will start to read the pattern string character-by-character using three char pointers: prev, cur, next. In particular, next is set to the current pattern plus two. The mistake was that next will still be a valid pointer when the pattern length is two, since the string is null-terminated. Make this inequality strict so these patterns work. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index 7ac0920..a87900d 100644
--- a/dir.c
+++ b/dir.c
@@ -682,7 +682,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
return;
}
- if (given->patternlen <= 2 ||
+ if (given->patternlen < 2 ||
*given->pattern == '*' ||
strstr(given->pattern, "**")) {
/* Not a cone pattern. */