mirror of
https://github.com/coreutils/coreutils.git
synced 2025-01-18 14:03:23 +08:00
fnmatch_loop.c (EXT, FCT): Use bool when appropriate.
(FCT): Use size_t, not unsigned int, for sizes. (EXT): Use ptrdiff_t, not int, for a variable that has to store a size-related quantity but might go negative. ptrdiff_t is good enough here, since in practice the value can't exceed SIZE_MAX/2.
This commit is contained in:
parent
a4805f79e8
commit
272dfbf173
@ -18,14 +18,14 @@
|
|||||||
/* Match STRING against the filename pattern PATTERN, returning zero if
|
/* Match STRING against the filename pattern PATTERN, returning zero if
|
||||||
it matches, nonzero if not. */
|
it matches, nonzero if not. */
|
||||||
static int EXT (INT opt, const CHAR *pattern, const CHAR *string,
|
static int EXT (INT opt, const CHAR *pattern, const CHAR *string,
|
||||||
const CHAR *string_end, int no_leading_period, int flags)
|
const CHAR *string_end, bool no_leading_period, int flags)
|
||||||
internal_function;
|
internal_function;
|
||||||
static const CHAR *END (const CHAR *patternp) internal_function;
|
static const CHAR *END (const CHAR *patternp) internal_function;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
internal_function
|
internal_function
|
||||||
FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
||||||
int no_leading_period, int flags)
|
bool no_leading_period, int flags)
|
||||||
{
|
{
|
||||||
register const CHAR *p = pattern, *n = string;
|
register const CHAR *p = pattern, *n = string;
|
||||||
register UCHAR c;
|
register UCHAR c;
|
||||||
@ -41,7 +41,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
|
|
||||||
while ((c = *p++) != L('\0'))
|
while ((c = *p++) != L('\0'))
|
||||||
{
|
{
|
||||||
int new_no_leading_period = 0;
|
bool new_no_leading_period = false;
|
||||||
c = FOLD (c);
|
c = FOLD (c);
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -161,9 +161,9 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
{
|
{
|
||||||
int flags2 = ((flags & FNM_FILE_NAME)
|
int flags2 = ((flags & FNM_FILE_NAME)
|
||||||
? flags : (flags & ~FNM_PERIOD));
|
? flags : (flags & ~FNM_PERIOD));
|
||||||
int no_leading_period2 = no_leading_period;
|
bool no_leading_period2 = no_leading_period;
|
||||||
|
|
||||||
for (--p; n < endp; ++n, no_leading_period2 = 0)
|
for (--p; n < endp; ++n, no_leading_period2 = false)
|
||||||
if (FCT (p, n, string_end, no_leading_period2, flags2)
|
if (FCT (p, n, string_end, no_leading_period2, flags2)
|
||||||
== 0)
|
== 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -186,7 +186,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
if (c == L('\\') && !(flags & FNM_NOESCAPE))
|
if (c == L('\\') && !(flags & FNM_NOESCAPE))
|
||||||
c = *p;
|
c = *p;
|
||||||
c = FOLD (c);
|
c = FOLD (c);
|
||||||
for (--p; n < endp; ++n, no_leading_period2 = 0)
|
for (--p; n < endp; ++n, no_leading_period2 = false)
|
||||||
if (FOLD ((UCHAR) *n) == c
|
if (FOLD ((UCHAR) *n) == c
|
||||||
&& (FCT (p, n, string_end, no_leading_period2, flags2)
|
&& (FCT (p, n, string_end, no_leading_period2, flags2)
|
||||||
== 0))
|
== 0))
|
||||||
@ -200,7 +200,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
case L('['):
|
case L('['):
|
||||||
{
|
{
|
||||||
/* Nonzero if the sense of the character class is inverted. */
|
/* Nonzero if the sense of the character class is inverted. */
|
||||||
register int not;
|
register bool not;
|
||||||
CHAR cold;
|
CHAR cold;
|
||||||
UCHAR fn;
|
UCHAR fn;
|
||||||
|
|
||||||
@ -410,10 +410,10 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
return FNM_NOMATCH;
|
return FNM_NOMATCH;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int is_range = 0;
|
bool is_range = false;
|
||||||
|
|
||||||
#ifdef _LIBC
|
#ifdef _LIBC
|
||||||
int is_seqval = 0;
|
bool is_seqval = false;
|
||||||
|
|
||||||
if (c == L('[') && *p == L('.'))
|
if (c == L('[') && *p == L('.'))
|
||||||
{
|
{
|
||||||
@ -460,7 +460,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
const int32_t *symb_table;
|
const int32_t *symb_table;
|
||||||
# ifdef WIDE_CHAR_VERSION
|
# ifdef WIDE_CHAR_VERSION
|
||||||
char str[c1];
|
char str[c1];
|
||||||
unsigned int strcnt;
|
size_t strcnt;
|
||||||
# else
|
# else
|
||||||
# define str (startp + 1)
|
# define str (startp + 1)
|
||||||
# endif
|
# endif
|
||||||
@ -550,7 +550,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the collation sequence value. */
|
/* Get the collation sequence value. */
|
||||||
is_seqval = 1;
|
is_seqval = true;
|
||||||
# ifdef WIDE_CHAR_VERSION
|
# ifdef WIDE_CHAR_VERSION
|
||||||
cold = wextra[1 + wextra[idx]];
|
cold = wextra[1 + wextra[idx]];
|
||||||
# else
|
# else
|
||||||
@ -629,7 +629,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
lcollseq = is_seqval ? cold : collseq[(UCHAR) cold];
|
lcollseq = is_seqval ? cold : collseq[(UCHAR) cold];
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
is_seqval = 0;
|
is_seqval = false;
|
||||||
if (cend == L('[') && *p == L('.'))
|
if (cend == L('[') && *p == L('.'))
|
||||||
{
|
{
|
||||||
uint32_t nrules =
|
uint32_t nrules =
|
||||||
@ -668,7 +668,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
const int32_t *symb_table;
|
const int32_t *symb_table;
|
||||||
# ifdef WIDE_CHAR_VERSION
|
# ifdef WIDE_CHAR_VERSION
|
||||||
char str[c1];
|
char str[c1];
|
||||||
unsigned int strcnt;
|
size_t strcnt;
|
||||||
# else
|
# else
|
||||||
# define str (startp + 1)
|
# define str (startp + 1)
|
||||||
# endif
|
# endif
|
||||||
@ -738,7 +738,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
wextra = (int32_t *) &extra[idx + 4];
|
wextra = (int32_t *) &extra[idx + 4];
|
||||||
# endif
|
# endif
|
||||||
/* Get the collation sequence value. */
|
/* Get the collation sequence value. */
|
||||||
is_seqval = 1;
|
is_seqval = true;
|
||||||
# ifdef WIDE_CHAR_VERSION
|
# ifdef WIDE_CHAR_VERSION
|
||||||
cend = wextra[1 + wextra[idx]];
|
cend = wextra[1 + wextra[idx]];
|
||||||
# else
|
# else
|
||||||
@ -929,7 +929,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
if (n == string_end || c != (UCHAR) *n)
|
if (n == string_end || c != (UCHAR) *n)
|
||||||
return FNM_NOMATCH;
|
return FNM_NOMATCH;
|
||||||
|
|
||||||
new_no_leading_period = 1;
|
new_no_leading_period = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
@ -996,10 +996,10 @@ END (const CHAR *pattern)
|
|||||||
static int
|
static int
|
||||||
internal_function
|
internal_function
|
||||||
EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
||||||
int no_leading_period, int flags)
|
bool no_leading_period, int flags)
|
||||||
{
|
{
|
||||||
const CHAR *startp;
|
const CHAR *startp;
|
||||||
int level;
|
ptrdiff_t level;
|
||||||
struct patternlist
|
struct patternlist
|
||||||
{
|
{
|
||||||
struct patternlist *next;
|
struct patternlist *next;
|
||||||
@ -1100,7 +1100,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
&& (FCT (p, rs, string_end,
|
&& (FCT (p, rs, string_end,
|
||||||
rs == string
|
rs == string
|
||||||
? no_leading_period
|
? no_leading_period
|
||||||
: rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0,
|
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
|
||||||
flags & FNM_FILE_NAME
|
flags & FNM_FILE_NAME
|
||||||
? flags : flags & ~FNM_PERIOD) == 0
|
? flags : flags & ~FNM_PERIOD) == 0
|
||||||
/* This didn't work. Try the whole pattern. */
|
/* This didn't work. Try the whole pattern. */
|
||||||
@ -1108,8 +1108,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
&& FCT (pattern - 1, rs, string_end,
|
&& FCT (pattern - 1, rs, string_end,
|
||||||
rs == string
|
rs == string
|
||||||
? no_leading_period
|
? no_leading_period
|
||||||
: (rs[-1] == '/' && NO_LEADING_PERIOD (flags)
|
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
|
||||||
? 1 : 0),
|
|
||||||
flags & FNM_FILE_NAME
|
flags & FNM_FILE_NAME
|
||||||
? flags : flags & ~FNM_PERIOD) == 0)))
|
? flags : flags & ~FNM_PERIOD) == 0)))
|
||||||
/* It worked. Signal success. */
|
/* It worked. Signal success. */
|
||||||
@ -1156,7 +1155,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|
|||||||
&& (FCT (p, rs, string_end,
|
&& (FCT (p, rs, string_end,
|
||||||
rs == string
|
rs == string
|
||||||
? no_leading_period
|
? no_leading_period
|
||||||
: rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0,
|
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
|
||||||
flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD)
|
flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD)
|
||||||
== 0))
|
== 0))
|
||||||
/* This is successful. */
|
/* This is successful. */
|
||||||
|
Loading…
Reference in New Issue
Block a user