summaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-09-12 07:10:59 +0000
committerJakub Jelinek <jakub@redhat.com>2005-09-12 07:10:59 +0000
commit5e6e144e096c83beefb5bd50ea22da7266e72aee (patch)
tree80b4ba2f5794225b6f0dbee4171394423dc82cf2 /posix
parent753ea4414a6a5994cf156d9a11582d18a1fb2a6f (diff)
Updated to fedora-glibc-20050912T0656
Diffstat (limited to 'posix')
-rw-r--r--posix/regcomp.c115
-rw-r--r--posix/regex.c31
-rw-r--r--posix/regex.h83
-rw-r--r--posix/regex_internal.c186
-rw-r--r--posix/regex_internal.h43
-rw-r--r--posix/regexec.c334
6 files changed, 421 insertions, 371 deletions
diff --git a/posix/regcomp.c b/posix/regcomp.c
index 37e06797ac..c93f79ea24 100644
--- a/posix/regcomp.c
+++ b/posix/regcomp.c
@@ -19,11 +19,11 @@
02111-1307 USA. */
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
- int length, reg_syntax_t syntax);
+ size_t length, reg_syntax_t syntax);
static void re_compile_fastmap_iter (regex_t *bufp,
const re_dfastate_t *init_state,
char *fastmap);
-static reg_errcode_t init_dfa (re_dfa_t *dfa, int pat_len);
+static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
static void init_word_char (re_dfa_t *dfa);
#ifdef RE_ENABLE_I18N
static void free_charset (re_charset_t *cset);
@@ -34,7 +34,6 @@ static reg_errcode_t create_initial_state (re_dfa_t *dfa);
static void optimize_utf8 (re_dfa_t *dfa);
#endif
static reg_errcode_t analyze (regex_t *preg);
-static reg_errcode_t create_initial_state (re_dfa_t *dfa);
static reg_errcode_t preorder (bin_tree_t *root,
reg_errcode_t (fn (void *, bin_tree_t *)),
void *extra);
@@ -51,9 +50,8 @@ static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node);
static reg_errcode_t duplicate_node_closure (re_dfa_t *dfa, int top_org_node,
int top_clone_node, int root_node,
unsigned int constraint);
-static reg_errcode_t duplicate_node (int *new_idx, re_dfa_t *dfa, int org_idx,
- unsigned int constraint);
-static int search_duplicated_node (re_dfa_t *dfa, int org_node,
+static int duplicate_node (re_dfa_t *dfa, int org_idx, unsigned int constraint);
+static int search_duplicated_node (const re_dfa_t *dfa, int org_node,
unsigned int constraint);
static reg_errcode_t calc_eclosure (re_dfa_t *dfa);
static reg_errcode_t calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa,
@@ -370,7 +368,7 @@ re_compile_fastmap_iter (bufp, init_state, fastmap)
int i, j, ch;
for (i = 0, ch = 0; i < BITSET_UINTS; ++i)
for (j = 0; j < UINT_BITS; ++j, ++ch)
- if (dfa->nodes[node].opr.sbcset[i] & (1 << j))
+ if (dfa->nodes[node].opr.sbcset[i] & (1u << j))
re_set_fastmap (fastmap, icase, ch);
}
#ifdef RE_ENABLE_I18N
@@ -536,8 +534,8 @@ weak_alias (__regcomp, regcomp)
size_t
regerror (errcode, preg, errbuf, errbuf_size)
int errcode;
- const regex_t *preg;
- char *errbuf;
+ const regex_t *__restrict preg;
+ char *__restrict errbuf;
size_t errbuf_size;
{
const char *msg;
@@ -742,7 +740,7 @@ static reg_errcode_t
re_compile_internal (preg, pattern, length, syntax)
regex_t *preg;
const char * pattern;
- int length;
+ size_t length;
reg_syntax_t syntax;
{
reg_errcode_t err = REG_NOERROR;
@@ -783,6 +781,7 @@ re_compile_internal (preg, pattern, length, syntax)
return err;
}
#ifdef DEBUG
+ /* Note: length+1 will not overflow since it is checked in init_dfa. */
dfa->re_str = re_malloc (char, length + 1);
strncpy (dfa->re_str, pattern, length + 1);
#endif
@@ -842,9 +841,9 @@ re_compile_internal (preg, pattern, length, syntax)
static reg_errcode_t
init_dfa (dfa, pat_len)
re_dfa_t *dfa;
- int pat_len;
+ size_t pat_len;
{
- int table_size;
+ unsigned int table_size;
#ifndef _LIBC
char *codeset_name;
#endif
@@ -854,13 +853,15 @@ init_dfa (dfa, pat_len)
/* Force allocation of str_tree_storage the first time. */
dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
+ /* Avoid overflows. */
+ if (pat_len == SIZE_MAX)
+ return REG_ESPACE;
+
dfa->nodes_alloc = pat_len + 1;
dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
- dfa->states_alloc = pat_len + 1;
-
/* table_size = 2 ^ ceil(log pat_len) */
- for (table_size = 1; table_size > 0; table_size <<= 1)
+ for (table_size = 1; ; table_size <<= 1)
if (table_size > pat_len)
break;
@@ -918,11 +919,11 @@ init_dfa (dfa, pat_len)
for (i = 0, ch = 0; i < BITSET_UINTS; ++i)
for (j = 0; j < UINT_BITS; ++j, ++ch)
{
- wchar_t wch = __btowc (ch);
+ wint_t wch = __btowc (ch);
if (wch != WEOF)
- dfa->sb_char[i] |= 1 << j;
+ dfa->sb_char[i] |= 1u << j;
# ifndef _LIBC
- if (isascii (ch) && wch != (wchar_t) ch)
+ if (isascii (ch) && wch != ch)
dfa->map_notascii = 1;
# endif
}
@@ -948,7 +949,7 @@ init_word_char (dfa)
for (i = 0, ch = 0; i < BITSET_UINTS; ++i)
for (j = 0; j < UINT_BITS; ++j, ++ch)
if (isalnum (ch) || ch == '_')
- dfa->word_char[i] |= 1 << j;
+ dfa->word_char[i] |= 1u << j;
}
/* Free the work area which are only used while compiling. */
@@ -1281,8 +1282,8 @@ optimize_subexps (extra, node)
node->left->parent = node;
dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
- if (other_idx < 8 * sizeof (dfa->used_bkref_map))
- dfa->used_bkref_map &= ~(1 << other_idx);
+ if (other_idx < CHAR_BIT * sizeof dfa->used_bkref_map)
+ dfa->used_bkref_map &= ~(1u << other_idx);
}
return REG_NOERROR;
@@ -1330,8 +1331,8 @@ lower_subexp (err, preg, node)
very common, so we do not lose much. An example that triggers
this case is the sed "script" /\(\)/x. */
&& node->left != NULL
- && (node->token.opr.idx >= 8 * sizeof (dfa->used_bkref_map)
- || !(dfa->used_bkref_map & (1 << node->token.opr.idx))))
+ && (node->token.opr.idx >= CHAR_BIT * sizeof dfa->used_bkref_map
+ || !(dfa->used_bkref_map & (1u << node->token.opr.idx))))
return node->left;
/* Convert the SUBEXP node to the concatenation of an
@@ -1469,7 +1470,6 @@ duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node,
int top_org_node, top_clone_node, root_node;
unsigned int init_constraint;
{
- reg_errcode_t err;
int org_node, clone_node, ret;
unsigned int constraint = init_constraint;
for (org_node = top_org_node, clone_node = top_clone_node;;)
@@ -1483,9 +1483,9 @@ duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node,
edests of the back reference. */
org_dest = dfa->nexts[org_node];
re_node_set_empty (dfa->edests + clone_node);
- err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
- if (BE (err != REG_NOERROR, 0))
- return err;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == -1, 0))
+ return REG_ESPACE;
dfa->nexts[clone_node] = dfa->nexts[org_node];
ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
if (BE (ret < 0, 0))
@@ -1521,9 +1521,9 @@ duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node,
}
constraint |= dfa->nodes[org_node].opr.ctx_type;
}
- err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
- if (BE (err != REG_NOERROR, 0))
- return err;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == -1, 0))
+ return REG_ESPACE;
ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
if (BE (ret < 0, 0))
return REG_ESPACE;
@@ -1539,9 +1539,10 @@ duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node,
if (clone_dest == -1)
{
/* There are no such a duplicated node, create a new one. */
- err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
- if (BE (err != REG_NOERROR, 0))
- return err;
+ reg_errcode_t err;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == -1, 0))
+ return REG_ESPACE;
ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
if (BE (ret < 0, 0))
return REG_ESPACE;
@@ -1560,9 +1561,9 @@ duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node,
}
org_dest = dfa->edests[org_node].elems[1];
- err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
- if (BE (err != REG_NOERROR, 0))
- return err;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == -1, 0))
+ return REG_ESPACE;
ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
if (BE (ret < 0, 0))
return REG_ESPACE;
@@ -1578,7 +1579,7 @@ duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node,
static int
search_duplicated_node (dfa, org_node, constraint)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
int org_node;
unsigned int constraint;
{
@@ -1593,27 +1594,27 @@ search_duplicated_node (dfa, org_node, constraint)
}
/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT.
- The new index will be stored in NEW_IDX and return REG_NOERROR if succeeded,
- otherwise return the error code. */
+ Return the index of the new node, or -1 if insufficient storage is
+ available. */
-static reg_errcode_t
-duplicate_node (new_idx, dfa, org_idx, constraint)
+static int
+duplicate_node (dfa, org_idx, constraint)
re_dfa_t *dfa;
- int *new_idx, org_idx;
+ int org_idx;
unsigned int constraint;
{
int dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
- if (BE (dup_idx == -1, 0))
- return REG_ESPACE;
- dfa->nodes[dup_idx].constraint = constraint;
- if (dfa->nodes[org_idx].type == ANCHOR)
- dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].opr.ctx_type;
- dfa->nodes[dup_idx].duplicated = 1;
-
- /* Store the index of the original node. */
- dfa->org_indices[dup_idx] = org_idx;
- *new_idx = dup_idx;
- return REG_NOERROR;
+ if (BE (dup_idx != -1, 1))
+ {
+ dfa->nodes[dup_idx].constraint = constraint;
+ if (dfa->nodes[org_idx].type == ANCHOR)
+ dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].opr.ctx_type;
+ dfa->nodes[dup_idx].duplicated = 1;
+
+ /* Store the index of the original node. */
+ dfa->org_indices[dup_idx] = org_idx;
+ }
+ return dup_idx;
}
static reg_errcode_t
@@ -2496,7 +2497,9 @@ parse_sub_exp (regexp, preg, token, syntax, nest, err)
if (BE (*err != REG_NOERROR, 0))
return NULL;
}
- dfa->completed_bkref_map |= 1 << cur_nsub;
+
+ if (cur_nsub <= '9' - '1')
+ dfa->completed_bkref_map |= 1 << cur_nsub;
tree = create_tree (dfa, tree, NULL, SUBEXP);
if (BE (tree == NULL, 0))
@@ -2683,7 +2686,9 @@ build_range_exp (sbcset, start_elem, end_elem)
# ifdef RE_ENABLE_I18N
{
- wchar_t wc, start_wc, end_wc;
+ wchar_t wc;
+ wint_t start_wc;
+ wint_t end_wc;
wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
diff --git a/posix/regex.c b/posix/regex.c
index 7a4f304cdd..d2d4f28e01 100644
--- a/posix/regex.c
+++ b/posix/regex.c
@@ -1,5 +1,5 @@
/* Extended regular expression matching and search library.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
@@ -22,28 +22,9 @@
#include "config.h"
#endif
-#ifdef _AIX
-#pragma alloca
-#else
-# ifndef allocax /* predefined by HP cc +Olibcalls */
-# ifdef __GNUC__
-# define alloca(size) __builtin_alloca (size)
-# else
-# if HAVE_ALLOCA_H
-# include <alloca.h>
-# else
-# ifdef __hpux
- void *alloca ();
-# else
-# if !defined __OS2__ && !defined WIN32
- char *alloca ();
-# else
-# include <malloc.h> /* OS/2 defines alloca in here */
-# endif
-# endif
-# endif
-# endif
-# endif
+/* Make sure noone compiles this code with a C++ compiler. */
+#ifdef __cplusplus
+# error "This is C code, use a C compiler"
#endif
#ifdef _LIBC
@@ -71,10 +52,6 @@
# include "../locale/localeinfo.h"
#endif
-/* POSIX says that <sys/types.h> must be included (by the caller) before
- <regex.h>. */
-#include <sys/types.h>
-
/* On some systems, limits.h sets RE_DUP_MAX to a lower value than
GNU regex allows. Include it before <regex.h>, which correctly
#undefs RE_DUP_MAX and sets it to the right value. */
diff --git a/posix/regex.h b/posix/regex.h
index 1f73d23866..e5ec398106 100644
--- a/posix/regex.h
+++ b/posix/regex.h
@@ -1,6 +1,6 @@
/* Definitions for data structures and routines for the regular
expression library.
- Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003
+ Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -452,38 +452,21 @@ typedef struct
/* Declarations for routines. */
-/* To avoid duplicating every routine declaration -- once with a
- prototype (if we are ANSI), and once without (if we aren't) -- we
- use the following macro to declare argument types. This
- unfortunately clutters up the declarations a bit, but I think it's
- worth it. */
-
-#if __STDC__
-
-# define _RE_ARGS(args) args
-
-#else /* not __STDC__ */
-
-# define _RE_ARGS(args) ()
-
-#endif /* not __STDC__ */
-
/* Sets the current default syntax to SYNTAX, and return the old syntax.
You can also simply assign to the `re_syntax_options' variable. */
-extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
+extern reg_syntax_t re_set_syntax (reg_syntax_t syntax);
/* Compile the regular expression PATTERN, with length LENGTH
and syntax given by the global `re_syntax_options', into the buffer
BUFFER. Return NULL if successful, and an error string if not. */
-extern const char *re_compile_pattern
- _RE_ARGS ((const char *pattern, size_t length,
- struct re_pattern_buffer *buffer));
+extern const char *re_compile_pattern (const char *pattern, size_t length,
+ struct re_pattern_buffer *buffer);
/* Compile a fastmap for the compiled pattern in BUFFER; used to
accelerate searches. Return 0 if successful and -2 if was an
internal error. */
-extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
+extern int re_compile_fastmap (struct re_pattern_buffer *buffer);
/* Search in the string STRING (with length LENGTH) for the pattern
@@ -491,31 +474,29 @@ extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
-extern int re_search
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
- int length, int start, int range, struct re_registers *regs));
+extern int re_search (struct re_pattern_buffer *buffer, const char *string,
+ int length, int start, int range,
+ struct re_registers *regs);
/* Like `re_search', but search in the concatenation of STRING1 and
STRING2. Also, stop searching at index START + STOP. */
-extern int re_search_2
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
- int length1, const char *string2, int length2,
- int start, int range, struct re_registers *regs, int stop));
+extern int re_search_2 (struct re_pattern_buffer *buffer, const char *string1,
+ int length1, const char *string2, int length2,
+ int start, int range, struct re_registers *regs,
+ int stop);
/* Like `re_search', but return how many characters in STRING the regexp
in BUFFER matched, starting at position START. */
-extern int re_match
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
- int length, int start, struct re_registers *regs));
+extern int re_match (struct re_pattern_buffer *buffer, const char *string,
+ int length, int start, struct re_registers *regs);
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
-extern int re_match_2
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
- int length1, const char *string2, int length2,
- int start, struct re_registers *regs, int stop));
+extern int re_match_2 (struct re_pattern_buffer *buffer, const char *string1,
+ int length1, const char *string2, int length2,
+ int start, struct re_registers *regs, int stop);
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
@@ -530,15 +511,15 @@ extern int re_match_2
Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */
-extern void re_set_registers
- _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
- unsigned num_regs, regoff_t *starts, regoff_t *ends));
+extern void re_set_registers (struct re_pattern_buffer *buffer,
+ struct re_registers *regs, unsigned num_regs,
+ regoff_t *starts, regoff_t *ends);
#if defined _REGEX_RE_COMP || defined _LIBC
# ifndef _CRAY
/* 4.2 bsd compatibility. */
-extern char *re_comp _RE_ARGS ((const char *));
-extern int re_exec _RE_ARGS ((const char *));
+extern char *re_comp (const char *);
+extern int re_exec (const char *);
# endif
#endif
@@ -563,19 +544,19 @@ extern int re_exec _RE_ARGS ((const char *));
#endif
/* POSIX compatibility. */
-extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
- const char *__restrict __pattern,
- int __cflags));
+extern int regcomp (regex_t *__restrict __preg,
+ const char *__restrict __pattern,
+ int __cflags);
-extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
- const char *__restrict __string, size_t __nmatch,
- regmatch_t __pmatch[__restrict_arr],
- int __eflags));
+extern int regexec (const regex_t *__restrict __preg,
+ const char *__restrict __string, size_t __nmatch,
+ regmatch_t __pmatch[__restrict_arr],
+ int __eflags);
-extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
- char *__errbuf, size_t __errbuf_size));
+extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
+ char *__restrict __errbuf, size_t __errbuf_size);
-extern void regfree _RE_ARGS ((regex_t *__preg));
+extern void regfree (regex_t *__preg);
#ifdef __cplusplus
diff --git a/posix/regex_internal.c b/posix/regex_internal.c
index baa58443ac..240e8872b3 100644
--- a/posix/regex_internal.c
+++ b/posix/regex_internal.c
@@ -26,16 +26,17 @@ static void re_string_construct_common (const char *str, int len,
static int re_string_skip_chars (re_string_t *pstr, int new_raw_idx,
wint_t *last_wc) internal_function;
#endif /* RE_ENABLE_I18N */
-static reg_errcode_t register_state (re_dfa_t *dfa, re_dfastate_t *newstate,
+static reg_errcode_t register_state (const re_dfa_t *dfa,
+ re_dfastate_t *newstate,
unsigned int hash) internal_function;
-static re_dfastate_t *create_ci_newstate (re_dfa_t *dfa,
+static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
const re_node_set *nodes,
unsigned int hash) internal_function;
-static re_dfastate_t *create_cd_newstate (re_dfa_t *dfa,
+static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
const re_node_set *nodes,
unsigned int context,
unsigned int hash) internal_function;
-static unsigned int inline calc_state_hash (const re_node_set *nodes,
+static inline unsigned int calc_state_hash (const re_node_set *nodes,
unsigned int context) internal_function;
/* Functions for string operation. */
@@ -148,26 +149,26 @@ re_string_realloc_buffers (pstr, new_buf_len)
#ifdef RE_ENABLE_I18N
if (pstr->mb_cur_max > 1)
{
- wint_t *new_array = re_realloc (pstr->wcs, wint_t, new_buf_len);
- if (BE (new_array == NULL, 0))
+ wint_t *new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
+ if (BE (new_wcs == NULL, 0))
return REG_ESPACE;
- pstr->wcs = new_array;
+ pstr->wcs = new_wcs;
if (pstr->offsets != NULL)
{
- int *new_array = re_realloc (pstr->offsets, int, new_buf_len);
- if (BE (new_array == NULL, 0))
+ int *new_offsets = re_realloc (pstr->offsets, int, new_buf_len);
+ if (BE (new_offsets == NULL, 0))
return REG_ESPACE;
- pstr->offsets = new_array;
+ pstr->offsets = new_offsets;
}
}
#endif /* RE_ENABLE_I18N */
if (pstr->mbs_allocated)
{
- unsigned char *new_array = re_realloc (pstr->mbs, unsigned char,
- new_buf_len);
- if (BE (new_array == NULL, 0))
+ unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char,
+ new_buf_len);
+ if (BE (new_mbs == NULL, 0))
return REG_ESPACE;
- pstr->mbs = new_array;
+ pstr->mbs = new_mbs;
}
pstr->bufs_len = new_buf_len;
return REG_NOERROR;
@@ -654,37 +655,50 @@ re_string_reconstruct (pstr, idx, eflags)
byte other than 0x80 - 0xbf. */
raw = pstr->raw_mbs + pstr->raw_mbs_idx;
end = raw + (offset - pstr->mb_cur_max);
- for (p = raw + offset - 1; p >= end; --p)
- if ((*p & 0xc0) != 0x80)
- {
- mbstate_t cur_state;
- wchar_t wc2;
- int mlen = raw + pstr->len - p;
- unsigned char buf[6];
-
- q = p;
- if (BE (pstr->trans != NULL, 0))
- {
- int i = mlen < 6 ? mlen : 6;
- while (--i >= 0)
- buf[i] = pstr->trans[p[i]];
- q = buf;
- }
- /* XXX Don't use mbrtowc, we know which conversion
- to use (UTF-8 -> UCS4). */
- memset (&cur_state, 0, sizeof (cur_state));
- mlen = (mbrtowc (&wc2, (const char *) p, mlen,
- &cur_state)
- - (raw + offset - p));
- if (mlen >= 0)
- {
- memset (&pstr->cur_state, '\0',
- sizeof (mbstate_t));
- pstr->valid_len = mlen;
- wc = wc2;
- }
- break;
- }
+ p = raw + offset - 1;
+#ifdef _LIBC
+ /* We know the wchar_t encoding is UCS4, so for the simple
+ case, ASCII characters, skip the conversion step. */
+ if (isascii (*p) && BE (pstr->trans == NULL, 1))
+ {
+ memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
+ pstr->valid_len = 0;
+ wc = (wchar_t) *p;
+ }
+ else
+#endif
+ for (; p >= end; --p)
+ if ((*p & 0xc0) != 0x80)
+ {
+ mbstate_t cur_state;
+ wchar_t wc2;
+ int mlen = raw + pstr->len - p;
+ unsigned char buf[6];
+ size_t mbclen;
+
+ q = p;
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i = mlen < 6 ? mlen : 6;
+ while (--i >= 0)
+ buf[i] = pstr->trans[p[i]];
+ q = buf;
+ }
+ /* XXX Don't use mbrtowc, we know which conversion
+ to use (UTF-8 -> UCS4). */
+ memset (&cur_state, 0, sizeof (cur_state));
+ mbclen = mbrtowc (&wc2, (const char *) p, mlen,
+ &cur_state);
+ if (raw + offset - p <= mbclen
+ && mbclen < (size_t) -2)
+ {
+ memset (&pstr->cur_state, '\0',
+ sizeof (mbstate_t));
+ pstr->valid_len = mbclen - (raw + offset - p);
+ wc = wc2;
+ }
+ break;
+ }
}
if (wc == WEOF)
@@ -738,15 +752,15 @@ re_string_reconstruct (pstr, idx, eflags)
}
else
#endif /* RE_ENABLE_I18N */
- if (BE (pstr->mbs_allocated, 0))
- {
- if (pstr->icase)
- build_upper_buffer (pstr);
- else if (pstr->trans != NULL)
- re_string_translate_buffer (pstr);
- }
- else
- pstr->valid_len = pstr->len;
+ if (BE (pstr->mbs_allocated, 0))
+ {
+ if (pstr->icase)
+ build_upper_buffer (pstr);
+ else if (pstr->trans != NULL)
+ re_string_translate_buffer (pstr);
+ }
+ else
+ pstr->valid_len = pstr->len;
pstr->cur_idx = 0;
return REG_NOERROR;
@@ -1227,12 +1241,12 @@ re_node_set_insert (set, elem)
/* Realloc if we need. */
if (set->alloc == set->nelem)
{
- int *new_array;
+ int *new_elems;
set->alloc = set->alloc * 2;
- new_array = re_realloc (set->elems, int, set->alloc);
- if (BE (new_array == NULL, 0))
+ new_elems = re_realloc (set->elems, int, set->alloc);
+ if (BE (new_elems == NULL, 0))
return -1;
- set->elems = new_array;
+ set->elems = new_elems;
}
/* Move the elements which follows the new element. Test the
@@ -1267,12 +1281,12 @@ re_node_set_insert_last (set, elem)
/* Realloc if we need. */
if (set->alloc == set->nelem)
{
- int *new_array;
+ int *new_elems;
set->alloc = (set->alloc + 1) * 2;
- new_array = re_realloc (set->elems, int, set->alloc);
- if (BE (new_array == NULL, 0))
+ new_elems = re_realloc (set->elems, int, set->alloc);
+ if (BE (new_elems == NULL, 0))
return -1;
- set->elems = new_array;
+ set->elems = new_elems;
}
/* Insert the new element. */
@@ -1345,15 +1359,19 @@ re_dfa_add_node (dfa, token)
int type = token.type;
if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
{
- int new_nodes_alloc = dfa->nodes_alloc * 2;
+ size_t new_nodes_alloc = dfa->nodes_alloc * 2;
int *new_nexts, *new_indices;
re_node_set *new_edests, *new_eclosures;
+ re_token_t *new_nodes;
- re_token_t *new_array = re_realloc (dfa->nodes, re_token_t,
- new_nodes_alloc);
- if (BE (new_array == NULL, 0))
+ /* Avoid overflows. */
+ if (BE (new_nodes_alloc < dfa->nodes_alloc, 0))
return -1;
- dfa->nodes = new_array;
+
+ new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
+ if (BE (new_nodes == NULL, 0))
+ return -1;
+ dfa->nodes = new_nodes;
new_nexts = re_realloc (dfa->nexts, int, new_nodes_alloc);
new_indices = re_realloc (dfa->org_indices, int, new_nodes_alloc);
new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
@@ -1379,7 +1397,7 @@ re_dfa_add_node (dfa, token)
return dfa->nodes_len++;
}
-static unsigned int inline
+static inline unsigned int
calc_state_hash (nodes, context)
const re_node_set *nodes;
unsigned int context;
@@ -1403,7 +1421,7 @@ calc_state_hash (nodes, context)
static re_dfastate_t*
re_acquire_state (err, dfa, nodes)
reg_errcode_t *err;
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
const re_node_set *nodes;
{
unsigned int hash;
@@ -1429,13 +1447,10 @@ re_acquire_state (err, dfa, nodes)
/* There are no appropriate state in the dfa, create the new one. */
new_state = create_ci_newstate (dfa, nodes, hash);
- if (BE (new_state != NULL, 1))
- return new_state;
- else
- {
- *err = REG_ESPACE;
- return NULL;
- }
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
}
/* Search for the state whose node_set is equivalent to NODES and
@@ -1451,7 +1466,7 @@ re_acquire_state (err, dfa, nodes)
static re_dfastate_t*
re_acquire_state_context (err, dfa, nodes, context)
reg_errcode_t *err;
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
const re_node_set *nodes;
unsigned int context;
{
@@ -1477,13 +1492,10 @@ re_acquire_state_context (err, dfa, nodes, context)
}
/* There are no appropriate state in `dfa', create the new one. */
new_state = create_cd_newstate (dfa, nodes, context, hash);
- if (BE (new_state != NULL, 1))
- return new_state;
- else
- {
- *err = REG_ESPACE;
- return NULL;
- }
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
}
/* Finish initialization of the new state NEWSTATE, and using its hash value
@@ -1492,7 +1504,7 @@ re_acquire_state_context (err, dfa, nodes, context)
static reg_errcode_t
register_state (dfa, newstate, hash)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
re_dfastate_t *newstate;
unsigned int hash;
{
@@ -1531,7 +1543,7 @@ register_state (dfa, newstate, hash)
static re_dfastate_t *
create_ci_newstate (dfa, nodes, hash)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
const re_node_set *nodes;
unsigned int hash;
{
@@ -1582,7 +1594,7 @@ create_ci_newstate (dfa, nodes, hash)
static re_dfastate_t *
create_cd_newstate (dfa, nodes, context, hash)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
const re_node_set *nodes;
unsigned int context, hash;
{
diff --git a/posix/regex_internal.h b/posix/regex_internal.h
index 6db384416a..debbe0db3b 100644
--- a/posix/regex_internal.h
+++ b/posix/regex_internal.h
@@ -91,8 +91,6 @@
# define inline
#endif
-/* Number of bits in a byte. */
-#define BYTE_BITS 8
/* Number of single byte character. */
#define SBC_MAX 256
@@ -123,16 +121,16 @@ extern const char __re_error_msgid[] attribute_hidden;
extern const size_t __re_error_msgid_idx[] attribute_hidden;
/* Number of bits in an unsinged int. */
-#define UINT_BITS (sizeof (unsigned int) * BYTE_BITS)
+#define UINT_BITS (sizeof (unsigned int) * CHAR_BIT)
/* Number of unsigned int in an bit_set. */
#define BITSET_UINTS ((SBC_MAX + UINT_BITS - 1) / UINT_BITS)
typedef unsigned int bitset[BITSET_UINTS];
typedef unsigned int *re_bitset_ptr_t;
typedef const unsigned int *re_const_bitset_ptr_t;
-#define bitset_set(set,i) (set[i / UINT_BITS] |= 1 << i % UINT_BITS)
-#define bitset_clear(set,i) (set[i / UINT_BITS] &= ~(1 << i % UINT_BITS))
-#define bitset_contain(set,i) (set[i / UINT_BITS] & (1 << i % UINT_BITS))
+#define bitset_set(set,i) (set[i / UINT_BITS] |= 1u << i % UINT_BITS)
+#define bitset_clear(set,i) (set[i / UINT_BITS] &= ~(1u << i % UINT_BITS))
+#define bitset_contain(set,i) (set[i / UINT_BITS] & (1u << i % UINT_BITS))
#define bitset_empty(set) memset (set, 0, sizeof (unsigned int) * BITSET_UINTS)
#define bitset_set_all(set) \
memset (set, 255, sizeof (unsigned int) * BITSET_UINTS)
@@ -430,6 +428,21 @@ static unsigned char re_string_fetch_byte_case (re_string_t *pstr)
#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
+#include <alloca.h>
+
+#ifndef _LIBC
+# if HAVE_ALLOCA
+/* The OS usually guarantees only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ allocate anything larger than 4096 bytes. Also care for the possibility
+ of a few compiler-allocated temporary stack slots. */
+# define __libc_use_alloca(n) ((n) < 4032)
+# else
+/* alloca is implemented with malloc, so just use malloc. */
+# define __libc_use_alloca(n) 0
+# endif
+#endif
+
#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
#define re_free(p) free (p)
@@ -541,7 +554,6 @@ typedef struct
{
int str_idx;
int node;
- int next_last_offset;
state_array_t *path;
int alasts; /* Allocation size of LASTS. */
int nlasts; /* The number of LASTS. */
@@ -564,9 +576,9 @@ typedef struct
/* The string object corresponding to the input string. */
re_string_t input;
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
- re_dfa_t *const dfa;
+ const re_dfa_t *const dfa;
#else
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
#endif
/* EFLAGS of the argument of regexec. */
int eflags;
@@ -613,8 +625,8 @@ struct re_fail_stack_t
struct re_dfa_t
{
re_token_t *nodes;
- int nodes_alloc;
- int nodes_len;
+ size_t nodes_alloc;
+ size_t nodes_len;
int *nexts;
int *org_indices;
re_node_set *edests;
@@ -632,7 +644,6 @@ struct re_dfa_t
/* number of subexpressions `re_nsub' is in regex_t. */
unsigned int state_hash_mask;
- int states_alloc;
int init_node;
int nbackref; /* The number of backreference in this dfa. */
@@ -688,10 +699,12 @@ static void re_node_set_remove_at (re_node_set *set, int idx) internal_function;
#define re_node_set_empty(p) ((p)->nelem = 0)
#define re_node_set_free(set) re_free ((set)->elems)
static int re_dfa_add_node (re_dfa_t *dfa, re_token_t token) internal_function;
-static re_dfastate_t *re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa,
- const re_node_set *nodes) internal_function;
+static re_dfastate_t *re_acquire_state (reg_errcode_t *err, const
+ re_dfa_t *dfa,
+ const re_node_set *nodes)
+ internal_function;
static re_dfastate_t *re_acquire_state_context (reg_errcode_t *err,
- re_dfa_t *dfa,
+ const re_dfa_t *dfa,
const re_node_set *nodes,
unsigned int context) internal_function;
static void free_state (re_dfastate_t *state) internal_function;
diff --git a/posix/regexec.c b/posix/regexec.c
index e635261d05..78042727f9 100644
--- a/posix/regexec.c
+++ b/posix/regexec.c
@@ -25,7 +25,7 @@ static void match_ctx_free (re_match_context_t *cache) internal_function;
static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, int node,
int str_idx, int from, int to)
internal_function;
-static int search_cur_bkref_entry (re_match_context_t *mctx, int str_idx)
+static int search_cur_bkref_entry (const re_match_context_t *mctx, int str_idx)
internal_function;
static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, int node,
int str_idx) internal_function;
@@ -58,14 +58,13 @@ static inline re_dfastate_t *acquire_init_state_context
static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
internal_function;
static int check_matching (re_match_context_t *mctx, int fl_longest_match,
- int *p_match_first)
- internal_function;
+ int *p_match_first) internal_function;
static int check_halt_node_context (const re_dfa_t *dfa, int node,
unsigned int context) internal_function;
static int check_halt_state_context (const re_match_context_t *mctx,
const re_dfastate_t *state, int idx)
internal_function;
-static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch,
+static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
regmatch_t *prev_idx_match, int cur_node,
int cur_idx, int nmatch) internal_function;
static int proceed_next_node (const re_match_context_t *mctx,
@@ -75,58 +74,73 @@ static int proceed_next_node (const re_match_context_t *mctx,
static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
int str_idx, int dest_node, int nregs,
regmatch_t *regs,
- re_node_set *eps_via_nodes) internal_function;
+ re_node_set *eps_via_nodes)
+ internal_function;
static int pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, int nregs,
- regmatch_t *regs, re_node_set *eps_via_nodes) internal_function;
+ regmatch_t *regs, re_node_set *eps_via_nodes)
+ internal_function;
static reg_errcode_t set_regs (const regex_t *preg,
const re_match_context_t *mctx,
size_t nmatch, regmatch_t *pmatch,
int fl_backtrack) internal_function;
-static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function;
+static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs)
+ internal_function;
#ifdef RE_ENABLE_I18N
static int sift_states_iter_mb (const re_match_context_t *mctx,
re_sift_context_t *sctx,
- int node_idx, int str_idx, int max_str_idx) internal_function;
+ int node_idx, int str_idx, int max_str_idx)
+ internal_function;
#endif /* RE_ENABLE_I18N */
-static reg_errcode_t sift_states_backward (re_match_context_t *mctx,
- re_sift_context_t *sctx) internal_function;
-static reg_errcode_t build_sifted_states (re_match_context_t *mctx,
+static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
+ re_sift_context_t *sctx)
+ internal_function;
+static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
re_sift_context_t *sctx, int str_idx,
- re_node_set *cur_dest) internal_function;
-static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx,
+ re_node_set *cur_dest)
+ internal_function;
+static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
re_sift_context_t *sctx,
int str_idx,
- re_node_set *dest_nodes) internal_function;
-static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa,
+ re_node_set *dest_nodes)
+ internal_function;
+static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
re_node_set *dest_nodes,
- const re_node_set *candidates) internal_function;
-static reg_errcode_t sub_epsilon_src_nodes (re_dfa_t *dfa, int node,
+ const re_node_set *candidates)
+ internal_function;
+static reg_errcode_t sub_epsilon_src_nodes (const re_dfa_t *dfa, int node,
re_node_set *dest_nodes,
- const re_node_set *and_nodes) internal_function;
-static int check_dst_limits (re_match_context_t *mctx, re_node_set *limits,
+ const re_node_set *and_nodes)
+ internal_function;
+static int check_dst_limits (const re_match_context_t *mctx,
+ re_node_set *limits,
int dst_node, int dst_idx, int src_node,
int src_idx) internal_function;
-static int check_dst_limits_calc_pos_1 (re_match_context_t *mctx,
+static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
int boundaries, int subexp_idx,
- int from_node, int bkref_idx) internal_function;
-static int check_dst_limits_calc_pos (re_match_context_t *mctx,
+ int from_node, int bkref_idx)
+ internal_function;
+static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
int limit, int subexp_idx,
int node, int str_idx,
int bkref_idx) internal_function;
-static reg_errcode_t check_subexp_limits (re_dfa_t *dfa,
+static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
re_node_set *dest_nodes,
const re_node_set *candidates,
re_node_set *limits,
struct re_backref_cache_entry *bkref_ents,
int str_idx) internal_function;
-static reg_errcode_t sift_states_bkref (re_match_context_t *mctx,
+static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
re_sift_context_t *sctx,
- int str_idx, const re_node_set *candidates) internal_function;
+ int str_idx, const re_node_set *candidates)
+ internal_function;
static reg_errcode_t clean_state_log_if_needed (re_match_context_t *mctx,
- int next_state_log_idx) internal_function;
-static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst,
- re_dfastate_t **src, int num) internal_function;
+ int next_state_log_idx)
+ internal_function;
+static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
+ re_dfastate_t **dst,
+ re_dfastate_t **src, int num)
+ internal_function;
static re_dfastate_t *find_recover_state (reg_errcode_t *err,
re_match_context_t *mctx) internal_function;
static re_dfastate_t *transit_state (reg_errcode_t *err,
@@ -134,27 +148,33 @@ static re_dfastate_t *transit_state (reg_errcode_t *err,
re_dfastate_t *state) internal_function;
static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
re_match_context_t *mctx,
- re_dfastate_t *next_state) internal_function;
+ re_dfastate_t *next_state)
+ internal_function;
static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
re_node_set *cur_nodes,
int str_idx) internal_function;
#if 0
static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
re_match_context_t *mctx,
- re_dfastate_t *pstate) internal_function;
+ re_dfastate_t *pstate)
+ internal_function;
#endif
#ifdef RE_ENABLE_I18N
static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
- re_dfastate_t *pstate) internal_function;
+ re_dfastate_t *pstate)
+ internal_function;
#endif /* RE_ENABLE_I18N */
static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
- const re_node_set *nodes) internal_function;
+ const re_node_set *nodes)
+ internal_function;
static reg_errcode_t get_subexp (re_match_context_t *mctx,
- int bkref_node, int bkref_str_idx) internal_function;
+ int bkref_node, int bkref_str_idx)
+ internal_function;
static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
const re_sub_match_top_t *sub_top,
re_sub_match_last_t *sub_last,
- int bkref_node, int bkref_str) internal_function;
+ int bkref_node, int bkref_str)
+ internal_function;
static int find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
int subexp_idx, int type) internal_function;
static reg_errcode_t check_arrival (re_match_context_t *mctx,
@@ -164,34 +184,41 @@ static reg_errcode_t check_arrival (re_match_context_t *mctx,
static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
int str_idx,
re_node_set *cur_nodes,
- re_node_set *next_nodes) internal_function;
-static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa,
+ re_node_set *next_nodes)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
re_node_set *cur_nodes,
- int ex_subexp, int type) internal_function;
-static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa,
+ int ex_subexp, int type)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
re_node_set *dst_nodes,
int target, int ex_subexp,
int type) internal_function;
static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
re_node_set *cur_nodes, int cur_str,
- int subexp_num, int type) internal_function;
-static int build_trtable (re_dfa_t *dfa,
+ int subexp_num, int type)
+ internal_function;
+static int build_trtable (const re_dfa_t *dfa,
re_dfastate_t *state) internal_function;
#ifdef RE_ENABLE_I18N
-static int check_node_accept_bytes (re_dfa_t *dfa, int node_idx,
- const re_string_t *input, int idx) internal_function;
+static int check_node_accept_bytes (const re_dfa_t *dfa, int node_idx,
+ const re_string_t *input, int idx)
+ internal_function;
# ifdef _LIBC
static unsigned int find_collation_sequence_value (const unsigned char *mbs,
- size_t name_len) internal_function;
+ size_t name_len)
+ internal_function;
# endif /* _LIBC */
#endif /* RE_ENABLE_I18N */
-static int group_nodes_into_DFAstates (re_dfa_t *dfa,
+static int group_nodes_into_DFAstates (const re_dfa_t *dfa,
const re_dfastate_t *state,
re_node_set *states_node,
bitset *states_ch) internal_function;
static int check_node_accept (const re_match_context_t *mctx,
- const re_token_t *node, int idx) internal_function;
-static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function;
+ const re_token_t *node, int idx)
+ internal_function;
+static reg_errcode_t extend_buffers (re_match_context_t *mctx)
+ internal_function;
/* Entry point for POSIX code. */
@@ -219,7 +246,7 @@ regexec (preg, string, nmatch, pmatch, eflags)
{
reg_errcode_t err;
int start, length;
- re_dfa_t *dfa = (re_dfa_t *)preg->buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
return REG_BADPAT;
@@ -373,8 +400,12 @@ re_search_2_stub (bufp, string1, length1, string2, length2, start, range, regs,
if (BE (s == NULL, 0))
return -2;
+#ifdef _LIBC
+ memcpy (__mempcpy (s, string1, length1), string2, length2);
+#else
memcpy (s, string1, length1);
memcpy (s + length1, string2, length2);
+#endif
str = s;
free_str = 1;
}
@@ -406,7 +437,7 @@ re_search_stub (bufp, string, length, start, range, stop, regs, ret_len)
regmatch_t *pmatch;
int nregs, rval;
int eflags = 0;
- re_dfa_t *dfa = (re_dfa_t *)bufp->buffer;
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
/* Check for out-of-range. */
if (BE (start < 0 || start > length, 0))
@@ -614,7 +645,7 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch,
regmatch_t pmatch[];
{
reg_errcode_t err;
- re_dfa_t *dfa = (re_dfa_t *)preg->buffer;
+ const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
int left_lim, right_lim, incr;
int fl_longest_match, match_first, match_kind, match_last = -1;
int extra_nmatch;
@@ -883,14 +914,14 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch,
#ifdef RE_ENABLE_I18N
if (BE (mctx.input.offsets_needed != 0, 0))
{
- if (pmatch[reg_idx].rm_so == mctx.input.valid_len)
- pmatch[reg_idx].rm_so += mctx.input.valid_raw_len - mctx.input.valid_len;
- else
- pmatch[reg_idx].rm_so = mctx.input.offsets[pmatch[reg_idx].rm_so];
- if (pmatch[reg_idx].rm_eo == mctx.input.valid_len)
- pmatch[reg_idx].rm_eo += mctx.input.valid_raw_len - mctx.input.valid_len;
- else
- pmatch[reg_idx].rm_eo = mctx.input.offsets[pmatch[reg_idx].rm_eo];
+ pmatch[reg_idx].rm_so =
+ (pmatch[reg_idx].rm_so == mctx.input.valid_len
+ ? mctx.input.valid_raw_len
+ : mctx.input.offsets[pmatch[reg_idx].rm_so]);
+ pmatch[reg_idx].rm_eo =
+ (pmatch[reg_idx].rm_eo == mctx.input.valid_len
+ ? mctx.input.valid_raw_len
+ : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
}
#else
assert (mctx.input.offsets_needed == 0);
@@ -927,7 +958,7 @@ static reg_errcode_t
prune_impossible_nodes (mctx)
re_match_context_t *mctx;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int halt_node, match_last;
reg_errcode_t ret;
re_dfastate_t **sifted_states;
@@ -1015,7 +1046,7 @@ acquire_init_state_context (err, mctx, idx)
const re_match_context_t *mctx;
int idx;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
if (dfa->init_state->has_constraint)
{
unsigned int context;
@@ -1054,11 +1085,11 @@ acquire_init_state_context (err, mctx, idx)
static int
check_matching (mctx, fl_longest_match, p_match_first)
- re_match_context_t *mctx;
- int fl_longest_match;
- int *p_match_first;
+ re_match_context_t *mctx;
+ int fl_longest_match;
+ int *p_match_first;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
int match = 0;
int match_last = -1;
@@ -1236,9 +1267,8 @@ proceed_next_node (mctx, nregs, regs, pidx, node, eps_via_nodes, fs)
re_node_set *eps_via_nodes;
struct re_fail_stack_t *fs;
{
- re_dfa_t *const dfa = mctx->dfa;
- int i, err, dest_node;
- dest_node = -1;
+ const re_dfa_t *const dfa = mctx->dfa;
+ int i, err;
if (IS_EPSILON_NODE (dfa->nodes[node].type))
{
re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
@@ -1304,6 +1334,7 @@ proceed_next_node (mctx, nregs, regs, pidx, node, eps_via_nodes, fs)
if (naccepted == 0)
{
+ int dest_node;
err = re_node_set_insert (eps_via_nodes, node);
if (BE (err < 0, 0))
return -2;
@@ -1317,7 +1348,7 @@ proceed_next_node (mctx, nregs, regs, pidx, node, eps_via_nodes, fs)
if (naccepted != 0
|| check_node_accept (mctx, dfa->nodes + node, *pidx))
{
- dest_node = dfa->nexts[node];
+ int dest_node = dfa->nexts[node];
*pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted;
if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
|| !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
@@ -1389,12 +1420,13 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack)
regmatch_t *pmatch;
int fl_backtrack;
{
- re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
int idx, cur_node;
re_node_set eps_via_nodes;
struct re_fail_stack_t *fs;
struct re_fail_stack_t fs_body = { 0, 2, NULL };
regmatch_t *prev_idx_match;
+ int prev_idx_match_malloced = 0;
#ifdef DEBUG
assert (nmatch > 1);
@@ -1413,7 +1445,18 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack)
cur_node = dfa->init_node;
re_node_set_init_empty (&eps_via_nodes);
- prev_idx_match = (regmatch_t *) alloca (sizeof (regmatch_t) * nmatch);
+ if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
+ prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
+ else
+ {
+ prev_idx_match = re_malloc (regmatch_t, nmatch);
+ if (prev_idx_match == NULL)
+ {
+ free_fail_stack_return (fs);
+ return REG_ESPACE;
+ }
+ prev_idx_match_malloced = 1;
+ }
memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
@@ -1431,6 +1474,8 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack)
if (reg_idx == nmatch)
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return free_fail_stack_return (fs);
}
cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
@@ -1439,6 +1484,8 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack)
else
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return REG_NOERROR;
}
}
@@ -1452,6 +1499,8 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack)
if (BE (cur_node == -2, 0))
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
free_fail_stack_return (fs);
return REG_ESPACE;
}
@@ -1461,11 +1510,15 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack)
else
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return REG_NOMATCH;
}
}
}
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return free_fail_stack_return (fs);
}
@@ -1488,7 +1541,7 @@ free_fail_stack_return (fs)
static void
update_regs (dfa, pmatch, prev_idx_match, cur_node, cur_idx, nmatch)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
regmatch_t *pmatch, *prev_idx_match;
int cur_node, cur_idx, nmatch;
{
@@ -1561,7 +1614,7 @@ update_regs (dfa, pmatch, prev_idx_match, cur_node, cur_idx, nmatch)
static reg_errcode_t
sift_states_backward (mctx, sctx)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
re_sift_context_t *sctx;
{
reg_errcode_t err;
@@ -1620,13 +1673,13 @@ sift_states_backward (mctx, sctx)
static reg_errcode_t
build_sifted_states (mctx, sctx, str_idx, cur_dest)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
re_sift_context_t *sctx;
int str_idx;
re_node_set *cur_dest;
{
- re_dfa_t *const dfa = mctx->dfa;
- re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
int i;
/* Then build the next sifted state.
@@ -1710,7 +1763,7 @@ clean_state_log_if_needed (mctx, next_state_log_idx)
static reg_errcode_t
merge_state_array (dfa, dst, src, num)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
re_dfastate_t **dst;
re_dfastate_t **src;
int num;
@@ -1739,12 +1792,12 @@ merge_state_array (dfa, dst, src, num)
static reg_errcode_t
update_cur_sifted_state (mctx, sctx, str_idx, dest_nodes)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
re_sift_context_t *sctx;
int str_idx;
re_node_set *dest_nodes;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
const re_node_set *candidates;
candidates = ((mctx->state_log[str_idx] == NULL) ? NULL
@@ -1788,7 +1841,7 @@ update_cur_sifted_state (mctx, sctx, str_idx, dest_nodes)
static reg_errcode_t
add_epsilon_src_nodes (dfa, dest_nodes, candidates)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
re_node_set *dest_nodes;
const re_node_set *candidates;
{
@@ -1814,7 +1867,7 @@ add_epsilon_src_nodes (dfa, dest_nodes, candidates)
static reg_errcode_t
sub_epsilon_src_nodes (dfa, node, dest_nodes, candidates)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
int node;
re_node_set *dest_nodes;
const re_node_set *candidates;
@@ -1865,11 +1918,11 @@ sub_epsilon_src_nodes (dfa, node, dest_nodes, candidates)
static int
check_dst_limits (mctx, limits, dst_node, dst_idx, src_node, src_idx)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
re_node_set *limits;
int dst_node, dst_idx, src_node, src_idx;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int lim_idx, src_pos, dst_pos;
int dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
@@ -1902,11 +1955,11 @@ check_dst_limits (mctx, limits, dst_node, dst_idx, src_node, src_idx)
static int
check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
int boundaries, subexp_idx, from_node, bkref_idx;
{
- re_dfa_t *const dfa = mctx->dfa;
- re_node_set *eclosures = dfa->eclosures + from_node;
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *eclosures = dfa->eclosures + from_node;
int node_idx;
/* Else, we are on the boundary: examine the nodes on the epsilon
@@ -1927,8 +1980,9 @@ check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx)
if (ent->node != node)
continue;
- if (subexp_idx <= 8 * sizeof (ent->eps_reachable_subexps_map)
- && !(ent->eps_reachable_subexps_map & (1 << subexp_idx)))
+ if (subexp_idx
+ < CHAR_BIT * sizeof ent->eps_reachable_subexps_map
+ && !(ent->eps_reachable_subexps_map & (1u << subexp_idx)))
continue;
/* Recurse trying to reach the OP_OPEN_SUBEXP and
@@ -1954,7 +2008,9 @@ check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx)
if (cpos == 0 && (boundaries & 2))
return 0;
- ent->eps_reachable_subexps_map &= ~(1 << subexp_idx);
+ if (subexp_idx
+ < CHAR_BIT * sizeof ent->eps_reachable_subexps_map)
+ ent->eps_reachable_subexps_map &= ~(1u << subexp_idx);
}
while (ent++->more);
}
@@ -1980,7 +2036,7 @@ check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx)
static int
check_dst_limits_calc_pos (mctx, limit, subexp_idx, from_node, str_idx, bkref_idx)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
int limit, subexp_idx, from_node, str_idx, bkref_idx;
{
struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
@@ -2009,7 +2065,7 @@ check_dst_limits_calc_pos (mctx, limit, subexp_idx, from_node, str_idx, bkref_id
static reg_errcode_t
check_subexp_limits (dfa, dest_nodes, candidates, limits, bkref_ents, str_idx)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
re_node_set *dest_nodes;
const re_node_set *candidates;
re_node_set *limits;
@@ -2100,12 +2156,12 @@ check_subexp_limits (dfa, dest_nodes, candidates, limits, bkref_ents, str_idx)
static reg_errcode_t
sift_states_bkref (mctx, sctx, str_idx, candidates)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
re_sift_context_t *sctx;
int str_idx;
const re_node_set *candidates;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
int node_idx, node;
re_sift_context_t local_sctx;
@@ -2133,7 +2189,10 @@ sift_states_bkref (mctx, sctx, str_idx, candidates)
enabled_idx = first_idx;
do
{
- int subexp_len, to_idx, dst_node;
+ int subexp_len;
+ int to_idx;
+ int dst_node;
+ int ret;
re_dfastate_t *cur_state;
if (entry->node != node)
@@ -2159,8 +2218,8 @@ sift_states_bkref (mctx, sctx, str_idx, candidates)
}
local_sctx.last_node = node;
local_sctx.last_str_idx = str_idx;
- err = re_node_set_insert (&local_sctx.limits, enabled_idx);
- if (BE (err < 0, 0))
+ ret = re_node_set_insert (&local_sctx.limits, enabled_idx);
+ if (BE (ret < 0, 0))
{
err = REG_ESPACE;
goto free_return;
@@ -2203,7 +2262,7 @@ sift_states_iter_mb (mctx, sctx, node_idx, str_idx, max_str_idx)
re_sift_context_t *sctx;
int node_idx, str_idx, max_str_idx;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int naccepted;
/* Check the node can accept `multi byte'. */
naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
@@ -2293,7 +2352,7 @@ merge_state_with_log (err, mctx, next_state)
re_match_context_t *mctx;
re_dfastate_t *next_state;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int cur_idx = re_string_cur_idx (&mctx->input);
if (cur_idx > mctx->state_log_top)
@@ -2372,7 +2431,7 @@ find_recover_state (err, mctx)
reg_errcode_t *err;
re_match_context_t *mctx;
{
- re_dfastate_t *cur_state = NULL;
+ re_dfastate_t *cur_state;
do
{
int max = mctx->state_log_top;
@@ -2388,7 +2447,7 @@ find_recover_state (err, mctx)
cur_state = merge_state_with_log (err, mctx, NULL);
}
- while (err == REG_NOERROR && cur_state == NULL);
+ while (*err == REG_NOERROR && cur_state == NULL);
return cur_state;
}
@@ -2405,7 +2464,7 @@ check_subexp_matching_top (mctx, cur_nodes, str_idx)
re_node_set *cur_nodes;
int str_idx;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int node_idx;
reg_errcode_t err;
@@ -2418,8 +2477,8 @@ check_subexp_matching_top (mctx, cur_nodes, str_idx)
{
int node = cur_nodes->elems[node_idx];
if (dfa->nodes[node].type == OP_OPEN_SUBEXP
- && dfa->nodes[node].opr.idx < (8 * sizeof (dfa->used_bkref_map))
- && dfa->used_bkref_map & (1 << dfa->nodes[node].opr.idx))
+ && dfa->nodes[node].opr.idx < CHAR_BIT * sizeof dfa->used_bkref_map
+ && dfa->used_bkref_map & (1u << dfa->nodes[node].opr.idx))
{
err = match_ctx_add_subtop (mctx, node, str_idx);
if (BE (err != REG_NOERROR, 0))
@@ -2439,7 +2498,7 @@ transit_state_sb (err, mctx, state)
re_match_context_t *mctx;
re_dfastate_t *state;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
re_node_set next_nodes;
re_dfastate_t *next_state;
int node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
@@ -2479,7 +2538,7 @@ transit_state_mb (mctx, pstate)
re_match_context_t *mctx;
re_dfastate_t *pstate;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
int i;
@@ -2532,7 +2591,8 @@ transit_state_mb (mctx, pstate)
if (BE (err != REG_NOERROR, 0))
return err;
}
- context = re_string_context_at (&mctx->input, dest_idx - 1, mctx->eflags);
+ context = re_string_context_at (&mctx->input, dest_idx - 1,
+ mctx->eflags);
mctx->state_log[dest_idx]
= re_acquire_state_context (&err, dfa, &dest_nodes, context);
if (dest_state != NULL)
@@ -2549,7 +2609,7 @@ transit_state_bkref (mctx, nodes)
re_match_context_t *mctx;
const re_node_set *nodes;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
int i;
int cur_str_idx = re_string_cur_idx (&mctx->input);
@@ -2664,14 +2724,15 @@ get_subexp (mctx, bkref_node, bkref_str_idx)
re_match_context_t *mctx;
int bkref_node, bkref_str_idx;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int subexp_num, sub_top_idx;
const char *buf = (const char *) re_string_get_buffer (&mctx->input);
/* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
int cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
if (cache_idx != -1)
{
- const struct re_backref_cache_entry *entry = mctx->bkref_ents + cache_idx;
+ const struct re_backref_cache_entry *entry
+ = mctx->bkref_ents + cache_idx;
do
if (entry->node == bkref_node)
return REG_NOERROR; /* We already checked it. */
@@ -2718,7 +2779,8 @@ get_subexp (mctx, bkref_node, bkref_str_idx)
buf = (const char *) re_string_get_buffer (&mctx->input);
}
if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
- break; /* We don't need to search this sub expression any more. */
+ /* We don't need to search this sub expression any more. */
+ break;
}
bkref_str_off += sl_str_diff;
sl_str += sl_str_diff;
@@ -2769,7 +2831,8 @@ get_subexp (mctx, bkref_node, bkref_str_idx)
continue;
/* Does this state have a ')' of the sub expression? */
nodes = &mctx->state_log[sl_str]->nodes;
- cls_node = find_subexp_node (dfa, nodes, subexp_num, OP_CLOSE_SUBEXP);
+ cls_node = find_subexp_node (dfa, nodes, subexp_num,
+ OP_CLOSE_SUBEXP);
if (cls_node == -1)
continue; /* No. */
if (sub_top->path == NULL)
@@ -2782,7 +2845,8 @@ get_subexp (mctx, bkref_node, bkref_str_idx)
/* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node
in the current context? */
err = check_arrival (mctx, sub_top->path, sub_top->node,
- sub_top->str_idx, cls_node, sl_str, OP_CLOSE_SUBEXP);
+ sub_top->str_idx, cls_node, sl_str,
+ OP_CLOSE_SUBEXP);
if (err == REG_NOMATCH)
continue;
if (BE (err != REG_NOERROR, 0))
@@ -2816,7 +2880,8 @@ get_subexp_sub (mctx, sub_top, sub_last, bkref_node, bkref_str)
int to_idx;
/* Can the subexpression arrive the back reference? */
err = check_arrival (mctx, &sub_last->path, sub_last->node,
- sub_last->str_idx, bkref_node, bkref_str, OP_OPEN_SUBEXP);
+ sub_last->str_idx, bkref_node, bkref_str,
+ OP_OPEN_SUBEXP);
if (err != REG_NOERROR)
return err;
err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
@@ -2865,7 +2930,7 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str,
state_array_t *path;
int top_node, top_str, last_node, last_str, type;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
int subexp_num, backup_cur_idx, str_idx, null_cnt;
re_dfastate_t *cur_state = NULL;
@@ -2881,7 +2946,7 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str,
int old_alloc = path->alloc;
path->alloc += last_str + mctx->max_mb_elem_len + 1;
new_array = re_realloc (path->array, re_dfastate_t *, path->alloc);
- if (new_array == NULL)
+ if (BE (new_array == NULL, 0))
{
path->alloc = old_alloc;
return REG_ESPACE;
@@ -2919,7 +2984,7 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str,
if (cur_state && cur_state->has_backref)
{
err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
- if (BE ( err != REG_NOERROR, 0))
+ if (BE (err != REG_NOERROR, 0))
return err;
}
else
@@ -2931,7 +2996,7 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str,
{
err = expand_bkref_cache (mctx, &next_nodes, str_idx,
subexp_num, type);
- if (BE ( err != REG_NOERROR, 0))
+ if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
return err;
@@ -2962,7 +3027,8 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str,
if (cur_state)
{
err = check_arrival_add_next_nodes (mctx, str_idx,
- &cur_state->non_eps_nodes, &next_nodes);
+ &cur_state->non_eps_nodes,
+ &next_nodes);
if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
@@ -2980,7 +3046,7 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str,
}
err = expand_bkref_cache (mctx, &next_nodes, str_idx,
subexp_num, type);
- if (BE ( err != REG_NOERROR, 0))
+ if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
return err;
@@ -3026,7 +3092,7 @@ check_arrival_add_next_nodes (mctx, str_idx, cur_nodes, next_nodes)
int str_idx;
re_node_set *cur_nodes, *next_nodes;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int result;
int cur_idx;
reg_errcode_t err;
@@ -3102,7 +3168,7 @@ check_arrival_add_next_nodes (mctx, str_idx, cur_nodes, next_nodes)
static reg_errcode_t
check_arrival_expand_ecl (dfa, cur_nodes, ex_subexp, type)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
re_node_set *cur_nodes;
int ex_subexp, type;
{
@@ -3121,7 +3187,7 @@ check_arrival_expand_ecl (dfa, cur_nodes, ex_subexp, type)
for (idx = 0; idx < cur_nodes->nelem; ++idx)
{
int cur_node = cur_nodes->elems[idx];
- re_node_set *eclosure = dfa->eclosures + cur_node;
+ const re_node_set *eclosure = dfa->eclosures + cur_node;
outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
if (outside_node == -1)
{
@@ -3156,7 +3222,7 @@ check_arrival_expand_ecl (dfa, cur_nodes, ex_subexp, type)
static reg_errcode_t
check_arrival_expand_ecl_sub (dfa, dst_nodes, target, ex_subexp, type)
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
int target, ex_subexp, type;
re_node_set *dst_nodes;
{
@@ -3206,7 +3272,7 @@ expand_bkref_cache (mctx, cur_nodes, cur_str, subexp_num,
int cur_str, subexp_num, type;
re_node_set *cur_nodes;
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
int cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
struct re_backref_cache_entry *ent;
@@ -3292,8 +3358,8 @@ expand_bkref_cache (mctx, cur_nodes, cur_str, subexp_num,
static int
build_trtable (dfa, state)
- re_dfa_t *dfa;
- re_dfastate_t *state;
+ const re_dfa_t *dfa;
+ re_dfastate_t *state;
{
reg_errcode_t err;
int i, j, ch, need_word_trtable = 0;
@@ -3310,12 +3376,10 @@ build_trtable (dfa, state)
from `state'. `dests_node[i]' represents the nodes which i-th
destination state contains, and `dests_ch[i]' represents the
characters which i-th destination state accepts. */
-#ifdef _LIBC
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX))
dests_node = (re_node_set *)
alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
else
-#endif
{
dests_node = (re_node_set *)
malloc ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
@@ -3349,13 +3413,11 @@ build_trtable (dfa, state)
if (BE (err != REG_NOERROR, 0))
goto out_free;
-#ifdef _LIBC
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX
+ ndests * 3 * sizeof (re_dfastate_t *)))
dest_states = (re_dfastate_t **)
alloca (ndests * 3 * sizeof (re_dfastate_t *));
else
-#endif
{
dest_states = (re_dfastate_t **)
malloc (ndests * 3 * sizeof (re_dfastate_t *));
@@ -3518,10 +3580,10 @@ out_free:
static int
group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch)
- re_dfa_t *dfa;
- const re_dfastate_t *state;
- re_node_set *dests_node;
- bitset *dests_ch;
+ const re_dfa_t *dfa;
+ const re_dfastate_t *state;
+ re_node_set *dests_node;
+ bitset *dests_ch;
{
reg_errcode_t err;
int result;
@@ -3710,9 +3772,9 @@ group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch)
static int
check_node_accept_bytes (dfa, node_idx, input, str_idx)
- re_dfa_t *dfa;
- int node_idx, str_idx;
- const re_string_t *input;
+ const re_dfa_t *dfa;
+ int node_idx, str_idx;
+ const re_string_t *input;
{
const re_token_t *node = dfa->nodes + node_idx;
int char_len, elem_len;
@@ -4244,7 +4306,7 @@ match_ctx_add_entry (mctx, node, str_idx, from, to)
static int
search_cur_bkref_entry (mctx, str_idx)
- re_match_context_t *mctx;
+ const re_match_context_t *mctx;
int str_idx;
{
int left, right, mid, last;