diff options
| -rw-r--r-- | src/attr_file.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/attr_file.c b/src/attr_file.c index aef3e64af..b2c60f204 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -560,6 +560,19 @@ void git_attr_path__free(git_attr_path *info) */ /* + * Determine the length of trailing spaces. + */ +static size_t trailing_space_length(const char *p, size_t len) +{ + size_t n; + for (n = len; n; n--) { + if (p[n-1] != ' ' && p[n-1] != '\t') + break; + } + return len - n; +} + +/* * This will return 0 if the spec was filled out, * GIT_ENOTFOUND if the fnmatch does not require matching, or * another error code there was an actual problem. @@ -646,9 +659,10 @@ int git_attr_fnmatch__parse( return GIT_ENOTFOUND; /* Remove trailing spaces. */ - while (pattern[spec->length - 1] == ' ' || pattern[spec->length - 1] == '\t') - if (--spec->length == 0) - return GIT_ENOTFOUND; + spec->length -= trailing_space_length(pattern, spec->length); + + if (spec->length == 0) + return GIT_ENOTFOUND; if (pattern[spec->length - 1] == '/') { spec->length--; |
