-/* Copyright (C) 1991-2013 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
it matches, nonzero if not. */
static int FCT (const CHAR *pattern, const CHAR *string,
const CHAR *string_end, int no_leading_period, int flags,
- struct STRUCT *ends, size_t alloca_used)
- internal_function;
+ struct STRUCT *ends, size_t alloca_used);
static int EXT (INT opt, const CHAR *pattern, const CHAR *string,
const CHAR *string_end, int no_leading_period, int flags,
- size_t alloca_used)
- internal_function;
-static const CHAR *END (const CHAR *patternp) internal_function;
+ size_t alloca_used);
+static const CHAR *END (const CHAR *patternp);
static int
-internal_function
-FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
- const CHAR *pattern;
- const CHAR *string;
- const CHAR *string_end;
- int no_leading_period;
- int flags;
- struct STRUCT *ends;
- size_t alloca_used;
+FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
+ int no_leading_period, int flags, struct STRUCT *ends, size_t alloca_used)
{
const CHAR *p = pattern, *n = string;
UCHAR c;
#ifdef _LIBC
else if (c == L('[') && *p == L('='))
{
- UCHAR str[1];
+ /* It's important that STR be a scalar variable rather
+ than a one-element array, because GCC (at least 4.9.2
+ -O2 on x86-64) can be confused by the array and
+ diagnose a "used initialized" in a dead branch in the
+ findidx function. */
+ UCHAR str;
uint32_t nrules =
_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
const CHAR *startp = p;
c = L('[');
goto normal_bracket;
}
- str[0] = c;
+ str = c;
c = *++p;
if (c != L('=') || p[1] != L(']'))
if (nrules == 0)
{
- if ((UCHAR) *n == str[0])
+ if ((UCHAR) *n == str)
goto matched;
}
else
const int32_t *table;
# if WIDE_CHAR_VERSION
const int32_t *weights;
- const int32_t *extra;
+ const wint_t *extra;
# else
const unsigned char *weights;
const unsigned char *extra;
# endif
const int32_t *indirect;
int32_t idx;
- const UCHAR *cp = (const UCHAR *) str;
-
- /* This #include defines a local function! */
-# if WIDE_CHAR_VERSION
-# include <locale/weightwc.h>
-# else
-# include <locale/weight.h>
-# endif
+ const UCHAR *cp = (const UCHAR *) &str;
# if WIDE_CHAR_VERSION
table = (const int32_t *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC);
weights = (const int32_t *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC);
- extra = (const int32_t *)
+ extra = (const wint_t *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC);
indirect = (const int32_t *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC);
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
# endif
- idx = findidx (&cp, 1);
+ idx = FINDIDX (table, indirect, extra, &cp, 1);
if (idx != 0)
{
/* We found a table entry. Now see whether the
int32_t idx2;
const UCHAR *np = (const UCHAR *) n;
- idx2 = findidx (&np, string_end - n);
+ idx2 = FINDIDX (table, indirect, extra,
+ &np, string_end - n);
if (idx2 != 0
&& (idx >> 24) == (idx2 >> 24)
&& len == weights[idx2 & 0xffffff])
{
int32_t table_size;
const int32_t *symb_table;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
char str[c1];
unsigned int strcnt;
# else
int32_t second;
int32_t hash;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
/* We have to convert the name to a single-byte
string. This is possible since the names
consist of ASCII characters and the internal
{
/* Compare the byte sequence but only if
this is not part of a range. */
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
int32_t *wextra;
idx += 1 + extra[idx];
if (! is_range)
{
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
for (c1 = 0;
(int32_t) c1 < wextra[idx];
++c1)
/* Get the collation sequence value. */
is_seqval = 1;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
cold = wextra[1 + wextra[idx]];
# else
/* Adjust for the alignment. */
uint32_t lcollseq;
UCHAR cend = *p++;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
/* Search in the `names' array for the characters. */
fcollseq = __collseq_table_lookup (collseq, fn);
if (fcollseq == ~((uint32_t) 0))
{
int32_t table_size;
const int32_t *symb_table;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
char str[c1];
unsigned int strcnt;
# else
int32_t second;
int32_t hash;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
/* We have to convert the name to a single-byte
string. This is possible since the names
consist of ASCII characters and the internal
{
/* Compare the byte sequence but only if
this is not part of a range. */
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
int32_t *wextra;
idx += 1 + extra[idx];
# endif
/* Get the collation sequence value. */
is_seqval = 1;
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
cend = wextra[1 + wextra[idx]];
# else
/* Adjust for the alignment. */
characters which are not mentioned in the
collation specification. */
if (
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
lcollseq == 0xffffffff ||
# endif
lcollseq <= fcollseq)
hcollseq = cend;
else
{
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
hcollseq =
__collseq_table_lookup (collseq, cend);
if (hcollseq == ~((uint32_t) 0))
if (lcollseq <= hcollseq && fcollseq <= hcollseq)
goto matched;
}
-# ifdef WIDE_CHAR_VERSION
+# if WIDE_CHAR_VERSION
range_not_matched:
# endif
#else
matched:
/* Skip the rest of the [...] that already matched. */
- do
+ while ((c = *p++) != L (']'))
{
- ignore_next:
- c = *p++;
-
if (c == L('\0'))
/* [... (unterminated) loses. */
return FNM_NOMATCH;
if (c < L('a') || c >= L('z'))
{
- p = startp;
- goto ignore_next;
+ p = startp - 2;
+ break;
}
}
p += 2;
- c = *p++;
}
else if (c == L('[') && *p == L('='))
{
if (c != L('=') || p[1] != L(']'))
return FNM_NOMATCH;
p += 2;
- c = *p++;
}
else if (c == L('[') && *p == L('.'))
{
- ++p;
while (1)
{
c = *++p;
- if (c == '\0')
+ if (c == L('\0'))
return FNM_NOMATCH;
- if (*p == L('.') && p[1] == L(']'))
+ if (c == L('.') && p[1] == L(']'))
break;
}
p += 2;
- c = *p++;
}
}
- while (c != L(']'));
if (not)
return FNM_NOMATCH;
}
static const CHAR *
-internal_function
END (const CHAR *pattern)
{
const CHAR *p = pattern;
}
else if ((*p == L('?') || *p == L('*') || *p == L('+') || *p == L('@')
|| *p == L('!')) && p[1] == L('('))
- p = END (p + 1);
+ {
+ p = END (p + 1);
+ if (*p == L('\0'))
+ /* This is an invalid pattern. */
+ return pattern;
+ }
else if (*p == L(')'))
break;
static int
-internal_function
EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
int no_leading_period, int flags, size_t alloca_used)
{
#undef STRCAT
#undef L
#undef BTOWC
+#undef WIDE_CHAR_VERSION
+#undef FINDIDX