* lib/regcomp.c (re_set_fastmap): ICASE arg is bool, not int.
All callers changed.
(calc_eclosure_iter): Likewise, for ROOT arg.
(parse_bracket_element): Likewise, for ACCEPT_HYPHEN arg.
(build_charclass_op): Likewise, for NON_MATCH arg.
* lib/regex_internal.c (re_string_allocate, re_string_construct):
(re_string_construct_common): Likewise, for ICASE arg.
* lib/regexec.c (re_search_2_stub, re_search_stub):
Likewise, for RET_LEN arg.
(check_matching): Likewise, for FL_LONGEST_MATCH arg.
(set_regs): Likewise, for FL_BACKTRACK arg.
* lib/regcomp.c (re_compile_fastmap_iter, optimize_utf8):
(duplicate_node_closure, calc_inveclosure, calc_eclosure):
(calc_eclosure_iter, parse_bracket_exp):
Use bool for internal variables that are booleans.
* lib/regexec.c (re_search_internal, check_matching):
(proceed_next_node):
(set_regs, build_sifted_states, sift_states_bkref):
(check_arrival_add_next_nodes, check_arrival_expand_ecl_sub):
(expand_bkref_cache, build_trtable, group_nodes_into_DFAstates):
(find_collation_sequence_value):
Likewise.
* lib/regex_internal.c (re_node_set_insert, re_node_set_insert_last):
(re_node_set_compare):
Return bool, not int. All callers changed.
* lib/regexec.c (check_halt_node_context, check_dst_limits):
(build_trtable, check_node_accept): Likewise.
* lib/regex_internal.h: Include stdbool.h.
Fix bugs uncovered when converting to bool.
* lib/regcomp.c (calc_eclosure_iter): Check for storage allocation
failure instead of charging ahead blindly.
* lib/regex_internal.c (register_state): Likewise.
* lib/regexec.c (re_search_2_stub): Use simpler method than boolean
for freeing internal storage.
(group_nodes_into_DFA_states): Use unsigned int, not int, for
bitset pieces used as boolean, to avoid undefined behavior
on hosts that do int overflow checking.
* config/srclist.txt: Add glibc bug 1285.
+2005-09-01 Paul Eggert <eggert@cs.ucla.edu>
+
+ * srclist.txt: Add glibc bug 1285.
+
2005-08-31 Paul Eggert <eggert@cs.ucla.edu>
* srclist.txt: Add glibc bugs 1273, 1278-1282, 1284.
-# $Id: srclist.txt,v 1.95 2005-09-01 07:03:01 eggert Exp $
+# $Id: srclist.txt,v 1.96 2005-09-01 19:41:07 eggert Exp $
# Files for which we are not the source. See ./srclistvars.sh for the
# variable definitions.
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1280
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1281
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1282
+# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1285
#$LIBCSRC/posix/regcomp.c lib gpl
#
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1238
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1281
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1282
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1284
+# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1285
#$LIBCSRC/posix/regex_internal.c lib gpl
#
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1054
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1273
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1278
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1281
+# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1285
#$LIBCSRC/posix/regex_internal.h lib gpl
#
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1216
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1281
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1282
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1284
+# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1285
#$LIBCSRC/posix/regexec.c lib gpl
#
# c89 changes $LIBCSRC/string/strdup.c lib gpl
+2005-09-01 Paul Eggert <eggert@cs.ucla.edu>
+
+ Use bool where appropriate.
+ * regcomp.c (re_set_fastmap): ICASE arg is bool, not int.
+ All callers changed.
+ (calc_eclosure_iter): Likewise, for ROOT arg.
+ (parse_bracket_element): Likewise, for ACCEPT_HYPHEN arg.
+ (build_charclass_op): Likewise, for NON_MATCH arg.
+ * regex_internal.c (re_string_allocate, re_string_construct):
+ (re_string_construct_common): Likewise, for ICASE arg.
+ * regexec.c (re_search_2_stub, re_search_stub):
+ Likewise, for RET_LEN arg.
+ (check_matching): Likewise, for FL_LONGEST_MATCH arg.
+ (set_regs): Likewise, for FL_BACKTRACK arg.
+ * regcomp.c (re_compile_fastmap_iter, optimize_utf8):
+ (duplicate_node_closure, calc_inveclosure, calc_eclosure):
+ (calc_eclosure_iter, parse_bracket_exp):
+ Use bool for internal variables that are booleans.
+ * regexec.c (re_search_internal, check_matching, proceed_next_node):
+ (set_regs, build_sifted_states, sift_states_bkref):
+ (check_arrival_add_next_nodes, check_arrival_expand_ecl_sub):
+ (expand_bkref_cache, build_trtable, group_nodes_into_DFAstates):
+ (find_collation_sequence_value):
+ Likewise.
+ * regex_internal.c (re_node_set_insert, re_node_set_insert_last):
+ (re_node_set_compare):
+ Return bool, not int. All callers changed.
+ * regexec.c (check_halt_node_context, check_dst_limits):
+ (build_trtable, check_node_accept): Likewise.
+ * regex_internal.h: Include stdbool.h.
+
+ Fix bugs uncovered when converting to bool.
+ * regcomp.c (calc_eclosure_iter): Check for storage allocation
+ failure instead of charging ahead blindly.
+ * regex_internal.c (register_state): Likewise.
+ * regexec.c (re_search_2_stub): Use simpler method than boolean
+ for freeing internal storage.
+ (group_nodes_into_DFA_states): Use unsigned int, not int, for
+ bitset pieces used as boolean, to avoid undefined behavior
+ on hosts that do int overflow checking.
+
2005-08-31 Derek Price <derek@ximbiot.com>
* getdelim.c (getdelim): Return EOF on EOF.
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,
- Idx node, int root);
+ Idx node, bool root);
static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
static Idx fetch_number (re_string_t *input, re_token_t *token,
reg_syntax_t syntax);
re_token_t *token, int token_len,
re_dfa_t *dfa,
reg_syntax_t syntax,
- int accept_hyphen);
+ bool accept_hyphen);
static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
re_string_t *regexp,
re_token_t *token);
unsigned REG_TRANSLATE_TYPE trans,
const unsigned char *class_name,
const unsigned char *extra,
- int non_match, reg_errcode_t *err);
+ bool non_match, reg_errcode_t *err);
static bin_tree_t *create_tree (re_dfa_t *dfa,
bin_tree_t *left, bin_tree_t *right,
re_token_type_t type);
static inline void
__attribute ((always_inline))
-re_set_fastmap (char *fastmap, int icase, int ch)
+re_set_fastmap (char *fastmap, bool icase, int ch)
{
fastmap[ch] = 1;
if (icase)
{
re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
Idx node_cnt;
- int icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE));
+ bool icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE));
for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
{
Idx node = init_state->nodes.elems[node_cnt];
&state) == p - buf
&& (__wcrtomb ((char *) buf, towlower (wc), &state)
!= (size_t) -1))
- re_set_fastmap (fastmap, 0, buf[0]);
+ re_set_fastmap (fastmap, false, buf[0]);
}
#endif
}
{
if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
!= (size_t) -1)
- re_set_fastmap (fastmap, 0, *(unsigned char *) buf);
+ re_set_fastmap (fastmap, false, *(unsigned char *) buf);
}
}
}
optimize_utf8 (re_dfa_t *dfa)
{
Idx node;
- int i, mb_chars = 0, has_period = 0;
+ int i;
+ bool mb_chars = false;
+ bool has_period = false;
for (node = 0; node < dfa->nodes_len; ++node)
switch (dfa->nodes[node].type)
{
case CHARACTER:
if (dfa->nodes[node].opr.c >= 0x80)
- mb_chars = 1;
+ mb_chars = true;
break;
case ANCHOR:
switch (dfa->nodes[node].opr.idx)
}
break;
case OP_PERIOD:
- has_period = 1;
+ has_period = true;
break;
case OP_BACK_REF:
case OP_ALT:
unsigned int init_constraint)
{
Idx org_node, clone_node;
- int ret;
+ bool ok;
unsigned int constraint = init_constraint;
for (org_node = top_org_node, clone_node = top_clone_node;;)
{
if (BE (clone_dest == REG_MISSING, 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))
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
else if (dfa->edests[org_node].nelem == 0)
/* ...but if the node is root_node itself, it means the
epsilon closure have a loop, then tie it to the
destination of the root_node. */
- ret = re_node_set_insert (dfa->edests + clone_node,
+ ok = re_node_set_insert (dfa->edests + clone_node,
org_dest);
- if (BE (ret < 0, 0))
+ if (BE (! ok, 0))
return REG_ESPACE;
break;
}
clone_dest = duplicate_node (dfa, org_dest, constraint);
if (BE (clone_dest == REG_MISSING, 0))
return REG_ESPACE;
- ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (ret < 0, 0))
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
else /* dfa->edests[org_node].nelem == 2 */
clone_dest = duplicate_node (dfa, org_dest, constraint);
if (BE (clone_dest == REG_MISSING, 0))
return REG_ESPACE;
- ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (ret < 0, 0))
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
return REG_ESPACE;
err = duplicate_node_closure (dfa, org_dest, clone_dest,
root_node, constraint);
{
/* There are a duplicated node which satisfy the constraint,
use it to avoid infinite loop. */
- ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (ret < 0, 0))
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
clone_dest = duplicate_node (dfa, org_dest, constraint);
if (BE (clone_dest == REG_MISSING, 0))
return REG_ESPACE;
- ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (ret < 0, 0))
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
org_node = org_dest;
calc_inveclosure (re_dfa_t *dfa)
{
Idx src, idx;
- int ret;
+ bool ok;
for (idx = 0; idx < dfa->nodes_len; ++idx)
re_node_set_init_empty (dfa->inveclosures + idx);
Idx *elems = dfa->eclosures[src].elems;
for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
{
- ret = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
- if (BE (ret == REG_MISSING, 0))
+ ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
}
calc_eclosure (re_dfa_t *dfa)
{
Idx node_idx;
- int incomplete;
+ bool incomplete;
#ifdef DEBUG
assert (dfa->nodes_len > 0);
#endif
- incomplete = 0;
+ incomplete = false;
/* For each nodes, calculate epsilon closure. */
for (node_idx = 0; ; ++node_idx)
{
{
if (!incomplete)
break;
- incomplete = 0;
+ incomplete = false;
node_idx = 0;
}
if (dfa->eclosures[node_idx].nelem != 0)
continue;
/* Calculate epsilon closure of `node_idx'. */
- err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, 1);
+ err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
if (BE (err != REG_NOERROR, 0))
return err;
if (dfa->eclosures[node_idx].nelem == 0)
{
- incomplete = 1;
+ incomplete = true;
re_node_set_free (&eclosure_elem);
}
}
/* Calculate epsilon closure of NODE. */
static reg_errcode_t
-calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, int root)
+calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
{
reg_errcode_t err;
unsigned int constraint;
Idx i;
- int incomplete;
+ bool incomplete;
+ bool ok;
re_node_set eclosure;
- incomplete = 0;
+ incomplete = false;
err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
if (BE (err != REG_NOERROR, 0))
return err;
return intermediate result. */
if (dfa->eclosures[edest].nelem == REG_MISSING)
{
- incomplete = 1;
+ incomplete = true;
continue;
}
/* If we haven't calculated the epsilon closure of `edest' yet,
calculate now. Otherwise use calculated epsilon closure. */
if (dfa->eclosures[edest].nelem == 0)
{
- err = calc_eclosure_iter (&eclosure_elem, dfa, edest, 0);
+ err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
if (BE (err != REG_NOERROR, 0))
return err;
}
the epsilon closure of this node is also incomplete. */
if (dfa->eclosures[edest].nelem == 0)
{
- incomplete = 1;
+ incomplete = true;
re_node_set_free (&eclosure_elem);
}
}
/* Epsilon closures include itself. */
- re_node_set_insert (&eclosure, node);
+ ok = re_node_set_insert (&eclosure, node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
if (incomplete && !root)
dfa->eclosures[node].nelem = 0;
else
Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
Idx equiv_class_alloc = 0, char_class_alloc = 0;
#endif /* not RE_ENABLE_I18N */
- int non_match = 0;
+ bool non_match = false;
bin_tree_t *work_tree;
int token_len;
- int first_round = 1;
+ bool first_round = true;
#ifdef _LIBC
collseqmb = (const unsigned char *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
#ifdef RE_ENABLE_I18N
mbcset->non_match = 1;
#endif /* not RE_ENABLE_I18N */
- non_match = 1;
+ non_match = true;
if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
bitset_set (sbcset, '\0');
re_string_skip_bytes (regexp, token_len); /* Skip a token. */
unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE];
unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE];
reg_errcode_t ret;
- int token_len2 = 0, is_range_exp = 0;
+ int token_len2 = 0;
+ bool is_range_exp = false;
re_token_t token2;
start_elem.opr.name = start_name_buf;
*err = ret;
goto parse_bracket_exp_free_return;
}
- first_round = 0;
+ first_round = false;
/* Get information about the next token. We need it in any case. */
token_len = peek_token_bracket (token, regexp, syntax);
token->type = CHARACTER;
}
else
- is_range_exp = 1;
+ is_range_exp = true;
}
}
- if (is_range_exp == 1)
+ if (is_range_exp == true)
{
end_elem.opr.name = end_name_buf;
ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
- dfa, syntax, 1);
+ dfa, syntax, true);
if (BE (ret != REG_NOERROR, 0))
{
*err = ret;
static reg_errcode_t
parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
re_token_t *token, int token_len, re_dfa_t *dfa,
- reg_syntax_t syntax, int accept_hyphen)
+ reg_syntax_t syntax, bool accept_hyphen)
{
#ifdef RE_ENABLE_I18N
int cur_char_size;
build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
const unsigned char *class_name,
const unsigned char *extra,
- int non_match, reg_errcode_t *err)
+ bool non_match, reg_errcode_t *err)
{
re_bitset_ptr_t sbcset;
#ifdef RE_ENABLE_I18N
static void re_string_construct_common (const char *str, Idx len,
re_string_t *pstr,
- REG_TRANSLATE_TYPE trans, int icase,
+ REG_TRANSLATE_TYPE trans, bool icase,
const re_dfa_t *dfa) internal_function;
static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
const re_node_set *nodes,
static reg_errcode_t
internal_function
re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
- REG_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa)
+ REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
{
reg_errcode_t ret;
Idx init_buf_len;
static reg_errcode_t
internal_function
re_string_construct (re_string_t *pstr, const char *str, Idx len,
- REG_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa)
+ REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
{
reg_errcode_t ret;
memset (pstr, '\0', sizeof (re_string_t));
static void
internal_function
re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
- REG_TRANSLATE_TYPE trans, int icase,
+ REG_TRANSLATE_TYPE trans, bool icase,
const re_dfa_t *dfa)
{
pstr->raw_mbs = (const unsigned char *) str;
pstr->len = len;
pstr->raw_len = len;
pstr->trans = (unsigned REG_TRANSLATE_TYPE) trans;
- pstr->icase = icase ? 1 : 0;
+ pstr->icase = icase;
pstr->mbs_allocated = (trans != NULL || icase);
pstr->mb_cur_max = dfa->mb_cur_max;
pstr->is_utf8 = dfa->is_utf8;
/* Insert the new element ELEM to the re_node_set* SET.
SET should not already have ELEM.
- return -1 if an error is occured, return 1 otherwise. */
+ Return true if successful. */
-static int
+static bool
internal_function
re_node_set_insert (re_node_set *set, Idx elem)
{
Idx idx;
/* In case the set is empty. */
if (set->alloc == 0)
- {
- if (BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1))
- return 1;
- else
- return -1;
- }
+ return re_node_set_init_1 (set, elem) == REG_NOERROR;
if (BE (set->nelem, 0) == 0)
{
/* We already guaranteed above that set->alloc != 0. */
set->elems[0] = elem;
++set->nelem;
- return 1;
+ return true;
}
/* Realloc if we need. */
set->alloc = set->alloc * 2;
new_elems = re_realloc (set->elems, Idx, set->alloc);
if (BE (new_elems == NULL, 0))
- return -1;
+ return false;
set->elems = new_elems;
}
/* Insert the new element. */
set->elems[idx] = elem;
++set->nelem;
- return 1;
+ return true;
}
/* Insert the new element ELEM to the re_node_set* SET.
SET should not already have any element greater than or equal to ELEM.
- Return -1 if an error is occured, return 1 otherwise. */
+ Return true if successful. */
-static int
+static bool
internal_function
re_node_set_insert_last (re_node_set *set, Idx elem)
{
set->alloc = (set->alloc + 1) * 2;
new_elems = re_realloc (set->elems, Idx, set->alloc);
if (BE (new_elems == NULL, 0))
- return -1;
+ return false;
set->elems = new_elems;
}
/* Insert the new element. */
set->elems[set->nelem++] = elem;
- return 1;
+ return true;
}
/* Compare two node sets SET1 and SET2.
- return 1 if SET1 and SET2 are equivalent, return 0 otherwise. */
+ Return true if SET1 and SET2 are equivalent. */
-static int
+static bool
internal_function __attribute ((pure))
re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
{
Idx i;
if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
- return 0;
+ return false;
for (i = set1->nelem ; REG_VALID_INDEX (--i) ; )
if (set1->elems[i] != set2->elems[i])
- return 0;
- return 1;
+ return false;
+ return true;
}
/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */
{
Idx elem = newstate->nodes.elems[i];
if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
- re_node_set_insert_last (&newstate->non_eps_nodes, elem);
+ {
+ bool ok = re_node_set_insert_last (&newstate->non_eps_nodes, elem);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
}
spot = dfa->state_table + (hash & dfa->state_hash_mask);
#include <assert.h>
#include <ctype.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned REG_TRANSLATE_TYPE trans;
/* Copy of re_dfa_t's word_char. */
re_const_bitset_ptr_t word_char;
- /* 1 if REG_ICASE. */
+ /* true if REG_ICASE. */
unsigned char icase;
unsigned char is_utf8;
unsigned char map_notascii;
const char *string2, Idx length2,
Idx start, regoff_t range,
struct re_registers *regs,
- Idx stop, int ret_len) internal_function;
+ Idx stop, bool ret_len) internal_function;
static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
const char *string, Idx length, Idx start,
regoff_t range, Idx stop,
struct re_registers *regs,
- int ret_len) internal_function;
+ bool ret_len) internal_function;
static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
Idx nregs, int regs_allocated) internal_function;
static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
internal_function;
-static Idx check_matching (re_match_context_t *mctx, int fl_longest_match,
+static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
Idx *p_match_first)
internal_function;
static Idx check_halt_state_context (const re_match_context_t *mctx,
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;
+ bool fl_backtrack) internal_function;
static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function;
#ifdef RE_ENABLE_I18N
static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa,
re_node_set *dest_nodes,
const re_node_set *candidates) internal_function;
-static int check_dst_limits (const re_match_context_t *mctx,
- const re_node_set *limits,
- Idx dst_node, Idx dst_idx, Idx src_node,
- Idx src_idx) internal_function;
+static bool check_dst_limits (const re_match_context_t *mctx,
+ const re_node_set *limits,
+ Idx dst_node, Idx dst_idx, Idx src_node,
+ Idx src_idx) internal_function;
static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
int boundaries, Idx subexp_idx,
Idx from_node, Idx bkref_idx) internal_function;
static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
re_node_set *cur_nodes, Idx cur_str,
Idx subexp_num, int type) internal_function;
-static int build_trtable (re_dfa_t *dfa,
- re_dfastate_t *state) internal_function;
+static bool build_trtable (re_dfa_t *dfa,
+ re_dfastate_t *state) internal_function;
#ifdef RE_ENABLE_I18N
static int check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
const re_string_t *input, Idx idx) internal_function;
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, Idx idx) internal_function;
+static bool check_node_accept (const re_match_context_t *mctx,
+ const re_token_t *node, Idx idx)
+ internal_function;
static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function;
\f
/* Entry point for POSIX code. */
re_match (struct re_pattern_buffer *bufp, const char *string,
Idx length, Idx start, struct re_registers *regs)
{
- return re_search_stub (bufp, string, length, start, 0, length, regs, 1);
+ return re_search_stub (bufp, string, length, start, 0, length, regs, true);
}
#ifdef _LIBC
weak_alias (__re_match, re_match)
re_search (struct re_pattern_buffer *bufp, const char *string,
Idx length, Idx start, regoff_t range, struct re_registers *regs)
{
- return re_search_stub (bufp, string, length, start, range, length, regs, 0);
+ return re_search_stub (bufp, string, length, start, range, length, regs,
+ false);
}
#ifdef _LIBC
weak_alias (__re_search, re_search)
Idx start, struct re_registers *regs, Idx stop)
{
return re_search_2_stub (bufp, string1, length1, string2, length2,
- start, 0, regs, stop, 1);
+ start, 0, regs, stop, true);
}
#ifdef _LIBC
weak_alias (__re_match_2, re_match_2)
Idx start, regoff_t range, struct re_registers *regs, Idx stop)
{
return re_search_2_stub (bufp, string1, length1, string2, length2,
- start, range, regs, stop, 0);
+ start, range, regs, stop, false);
}
#ifdef _LIBC
weak_alias (__re_search_2, re_search_2)
const char *string1, Idx length1,
const char *string2, Idx length2,
Idx start, regoff_t range, struct re_registers *regs,
- Idx stop, int ret_len)
+ Idx stop, bool ret_len)
{
const char *str;
regoff_t rval;
Idx len = length1 + length2;
- int free_str = 0;
+ char *s = NULL;
if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
return -2;
if (length2 > 0)
if (length1 > 0)
{
- char *s = re_malloc (char, len);
+ s = re_malloc (char, len);
if (BE (s == NULL, 0))
return -2;
memcpy (s, string1, length1);
memcpy (s + length1, string2, length2);
str = s;
- free_str = 1;
}
else
str = string2;
rval = re_search_stub (bufp, str, len, start, range, stop, regs,
ret_len);
- if (free_str)
- re_free ((char *) str);
+ re_free (s);
return rval;
}
/* The parameters have the same meaning as those of re_search.
Additional parameters:
- If RET_LEN is nonzero the length of the match is returned (re_match style);
+ If RET_LEN is true the length of the match is returned (re_match style);
otherwise the position of the match is returned. */
static regoff_t
re_search_stub (struct re_pattern_buffer *bufp,
const char *string, Idx length,
Idx start, regoff_t range, Idx stop, struct re_registers *regs,
- int ret_len)
+ bool ret_len)
{
reg_errcode_t result;
regmatch_t *pmatch;
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
Idx left_lim, right_lim;
int incr;
- int fl_longest_match, match_kind;
+ bool fl_longest_match;
+ int match_kind;
Idx match_first, match_last = REG_MISSING;
Idx extra_nmatch;
- int sb, ch;
+ bool sb;
+ int ch;
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
re_match_context_t mctx = { .dfa = dfa };
#else
static Idx
internal_function
-check_matching (re_match_context_t *mctx, int fl_longest_match,
+check_matching (re_match_context_t *mctx, bool fl_longest_match,
Idx *p_match_first)
{
re_dfa_t *const dfa = mctx->dfa;
Idx match_last = REG_MISSING;
Idx cur_str_idx = re_string_cur_idx (&mctx->input);
re_dfastate_t *cur_state;
- int at_init_state = p_match_first != NULL;
+ bool at_init_state = p_match_first != NULL;
Idx next_start_idx = cur_str_idx;
err = REG_NOERROR;
later. E.g. Processing back references. */
if (BE (dfa->nbackref, 0))
{
- at_init_state = 0;
+ at_init_state = false;
err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
if (BE (err != REG_NOERROR, 0))
return err;
if (old_state == cur_state)
next_start_idx = next_char_idx;
else
- at_init_state = 0;
+ at_init_state = false;
}
if (cur_state->halt)
/* Check NODE match the current context. */
-static int
+static bool
internal_function
check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
{
re_token_type_t type = dfa->nodes[node].type;
unsigned int constraint = dfa->nodes[node].constraint;
if (type != END_OF_RE)
- return 0;
+ return false;
if (!constraint)
- return 1;
+ return true;
if (NOT_SATISFY_NEXT_CONSTRAINT (constraint, context))
- return 0;
- return 1;
+ return false;
+ return true;
}
/* Check the halt state STATE match the current context.
{
re_dfa_t *const dfa = mctx->dfa;
Idx i;
- int err;
+ bool ok;
if (IS_EPSILON_NODE (dfa->nodes[node].type))
{
re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
re_node_set *edests = &dfa->edests[node];
Idx dest_node;
- err = re_node_set_insert (eps_via_nodes, node);
- if (BE (err < 0, 0))
+ ok = re_node_set_insert (eps_via_nodes, node);
+ if (BE (! ok, 0))
return REG_ERROR;
/* Pick up a valid destination, or return REG_MISSING if none
is found. */
if (naccepted == 0)
{
Idx dest_node;
- err = re_node_set_insert (eps_via_nodes, node);
- if (BE (err < 0, 0))
+ ok = re_node_set_insert (eps_via_nodes, node);
+ if (BE (! ok, 0))
return REG_ERROR;
dest_node = dfa->edests[node].elems[0];
if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
static reg_errcode_t
internal_function
set_regs (const regex_t *preg, const re_match_context_t *mctx,
- size_t nmatch, regmatch_t *pmatch, int fl_backtrack)
+ size_t nmatch, regmatch_t *pmatch, bool fl_backtrack)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
Idx idx, cur_node;
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;
+ bool prev_idx_match_malloced = false;
#ifdef DEBUG
assert (nmatch > 1);
free_fail_stack_return (fs);
return REG_ESPACE;
}
- prev_idx_match_malloced = 1;
+ prev_idx_match_malloced = true;
}
memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
{
Idx prev_node = cur_src->elems[i];
int naccepted = 0;
- int ret;
+ bool ok;
#ifdef DEBUG
re_token_type_t type = dfa->nodes[prev_node].type;
prev_node, str_idx))
continue;
}
- ret = re_node_set_insert (cur_dest, prev_node);
- if (BE (ret == -1, 0))
+ ok = re_node_set_insert (cur_dest, prev_node);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
return REG_NOERROR;
}
-static int
+static bool
internal_function
check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
if (src_pos == dst_pos)
continue; /* This is unrelated limitation. */
else
- return 1;
+ return true;
}
- return 0;
+ return false;
}
static int
enabled_idx = first_idx;
do
{
- Idx subexp_len, to_idx, dst_node, ret;
+ bool ok;
+ Idx subexp_len, to_idx, dst_node;
re_dfastate_t *cur_state;
if (entry->node != node)
}
local_sctx.last_node = node;
local_sctx.last_str_idx = str_idx;
- ret = re_node_set_insert (&local_sctx.limits, enabled_idx);
- if (BE (ret < 0, 0))
+ ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
+ if (BE (! ok, 0))
{
err = REG_ESPACE;
goto free_return;
re_node_set *next_nodes)
{
re_dfa_t *const dfa = mctx->dfa;
- int result;
+ bool ok;
Idx cur_idx;
reg_errcode_t err;
re_node_set union_set;
return err;
}
}
- result = re_node_set_insert (&union_set, next_node);
- if (BE (result < 0, 0))
+ ok = re_node_set_insert (&union_set, next_node);
+ if (BE (! ok, 0))
{
re_node_set_free (&union_set);
return REG_ESPACE;
if (naccepted
|| check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
{
- result = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
- if (BE (result < 0, 0))
+ ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
+ if (BE (! ok, 0))
{
re_node_set_free (&union_set);
return REG_ESPACE;
Idx cur_node;
for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);)
{
- int err;
+ bool ok;
if (dfa->nodes[cur_node].type == type
&& dfa->nodes[cur_node].opr.idx == ex_subexp)
{
if (type == OP_CLOSE_SUBEXP)
{
- err = re_node_set_insert (dst_nodes, cur_node);
- if (BE (err == -1, 0))
+ ok = re_node_set_insert (dst_nodes, cur_node);
+ if (BE (! ok, 0))
return REG_ESPACE;
}
break;
}
- err = re_node_set_insert (dst_nodes, cur_node);
- if (BE (err == -1, 0))
+ ok = re_node_set_insert (dst_nodes, cur_node);
+ if (BE (! ok, 0))
return REG_ESPACE;
if (dfa->edests[cur_node].nelem == 0)
break;
next_node = dfa->nexts[ent->node];
if (mctx->state_log[to_idx])
{
- int ret;
+ bool ok;
if (re_node_set_contains (&mctx->state_log[to_idx]->nodes,
next_node))
continue;
err = re_node_set_init_copy (&union_set,
&mctx->state_log[to_idx]->nodes);
- ret = re_node_set_insert (&union_set, next_node);
- if (BE (err != REG_NOERROR || ret < 0, 0))
+ ok = re_node_set_insert (&union_set, next_node);
+ if (BE (err != REG_NOERROR || ! ok, 0))
{
re_node_set_free (&union_set);
err = err != REG_NOERROR ? err : REG_ESPACE;
}
/* Build transition table for the state.
- Return 1 if succeeded, otherwise return NULL. */
+ Return true if successful. */
-static int
+static bool
internal_function
build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
{
reg_errcode_t err;
Idx i, j;
- int ch, need_word_trtable = 0;
+ int ch;
+ bool need_word_trtable = false;
unsigned int elem, mask;
- int dests_node_malloced = 0, dest_states_malloced = 0;
+ bool dests_node_malloced = false, dest_states_malloced = false;
Idx ndests; /* Number of the destination states from `state'. */
re_dfastate_t **trtable;
re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
dests_node = (re_node_set *)
malloc ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
if (BE (dests_node == NULL, 0))
- return 0;
- dests_node_malloced = 1;
+ return false;
+ dests_node_malloced = true;
}
dests_ch = (bitset *) (dests_node + SBC_MAX);
{
if (dests_node_malloced)
free (dests_node);
- /* Return 0 in case of an error, 1 otherwise. */
if (ndests == 0)
{
state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
err = re_node_set_alloc (&follows, ndests + 1);
re_node_set_free (dests_node + i);
if (dests_node_malloced)
free (dests_node);
- return 0;
+ return false;
}
- dest_states_malloced = 1;
+ dest_states_malloced = true;
}
dest_states_word = dest_states + ndests;
dest_states_nl = dest_states_word + ndests;
goto out_free;
if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
- need_word_trtable = 1;
+ need_word_trtable = true;
dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
CONTEXT_NEWLINE);
if (dests_node_malloced)
free (dests_node);
- return 1;
+ return true;
}
/* Group all nodes belonging to STATE into several destinations.
re_node_set *dests_node, bitset *dests_ch)
{
reg_errcode_t err;
- int result;
+ bool ok;
Idx i, j, k;
Idx ndests; /* Number of the destinations from `state'. */
bitset accepts; /* Characters a node can accept. */
{
if (constraint & NEXT_NEWLINE_CONSTRAINT)
{
- int accepts_newline = bitset_contain (accepts, NEWLINE_CHAR);
+ unsigned int accepts_newline =
+ bitset_contain (accepts, NEWLINE_CHAR);
bitset_empty (accepts);
if (accepts_newline)
bitset_set (accepts, NEWLINE_CHAR);
bitset intersec; /* Intersection sets, see below. */
bitset remains;
/* Flags, see below. */
- int has_intersec, not_subset, not_consumed;
+ unsigned int has_intersec, not_subset, not_consumed;
/* Optimization, skip if this state doesn't accept the character. */
if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
}
/* Put the position in the current group. */
- result = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
- if (BE (result < 0, 0))
+ ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
+ if (BE (! ok, 0))
goto error_return;
/* If all characters are consumed, go to next node. */
for (idx = 0; idx < extrasize;)
{
- int mbs_cnt, found = 0;
+ int mbs_cnt;
+ bool found = false;
int32_t elem_mbs_len;
/* Skip the name of collating element name. */
idx = idx + extra[idx] + 1;
break;
if (mbs_cnt == elem_mbs_len)
/* Found the entry. */
- found = 1;
+ found = true;
}
/* Skip the byte sequence of the collating element. */
idx += elem_mbs_len;
/* Check whether the node accepts the byte which is IDX-th
byte of the INPUT. */
-static int
+static bool
internal_function
check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
Idx idx)
{
case CHARACTER:
if (node->opr.c != ch)
- return 0;
+ return false;
break;
case SIMPLE_BRACKET:
if (!bitset_contain (node->opr.sbcset, ch))
- return 0;
+ return false;
break;
#ifdef RE_ENABLE_I18N
case OP_UTF8_PERIOD:
if (ch >= 0x80)
- return 0;
+ return false;
/* FALLTHROUGH */
#endif
case OP_PERIOD:
if ((ch == '\n' && !(mctx->dfa->syntax & REG_DOT_NEWLINE))
|| (ch == '\0' && (mctx->dfa->syntax & REG_DOT_NOT_NULL)))
- return 0;
+ return false;
break;
default:
- return 0;
+ return false;
}
if (node->constraint)
unsigned int context = re_string_context_at (&mctx->input, idx,
mctx->eflags);
if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* Extend the buffers, if the buffers have run out. */