]> git.ipfire.org Git - thirdparty/git.git/commit - dir.c
dir.c::match_basename(): pay attention to the length of string parameters
authorJunio C Hamano <gitster@pobox.com>
Thu, 28 Mar 2013 21:47:28 +0000 (17:47 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Mar 2013 04:48:12 +0000 (21:48 -0700)
commit0b6e56dfe6c7f75c2a02cc0cf8731c9e62b6d3d1
tree412658ee18221a111f188f765f4223243c8712f0
parentdc09e9ec43c09cdf803cc4f39f1fcb8ebcf80eb1
dir.c::match_basename(): pay attention to the length of string parameters

The function takes two counted strings (<basename, basenamelen> and
<pattern, patternlen>) as parameters, together with prefix (the
length of the prefix in pattern that is to be matched literally
without globbing against the basename) and EXC_* flags that tells it
how to match the pattern against the basename.

However, it did not pay attention to the length of these counted
strings.  Update them to do the following:

 * When the entire pattern is to be matched literally, the pattern
   matches the basename only when the lengths of them are the same,
   and they match up to that length.

 * When the pattern is "*" followed by a string to be matched
   literally, make sure that the basenamelen is equal or longer than
   the "literal" part of the pattern, and the tail of the basename
   string matches that literal part.

 * Otherwise, use the new fnmatch_icase_mem helper to make
   sure we only lookmake sure we use only look at the
   counted part of the strings.  Because these counted strings are
   full strings most of the time, we check for termination
   to avoid unnecessary allocation.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c