From: Paul Eggert Date: Thu, 1 Sep 2005 19:41:07 +0000 (+0000) Subject: Use bool where appropriate. X-Git-Tag: cvs-readonly~2991 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=1e5cfc92d3a783d911169d1704ae6e37072c327c;p=gnulib.git Use bool where appropriate. * 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. --- diff --git a/config/ChangeLog b/config/ChangeLog index 979310599..d933a19d8 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2005-09-01 Paul Eggert + + * srclist.txt: Add glibc bug 1285. + 2005-08-31 Paul Eggert * srclist.txt: Add glibc bugs 1273, 1278-1282, 1284. diff --git a/config/srclist.txt b/config/srclist.txt index 8f841a3c1..b6cfcf2ea 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -1,4 +1,4 @@ -# $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. @@ -107,6 +107,7 @@ $LIBCSRC/stdlib/getsubopt.c lib gpl # 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 @@ -133,6 +134,7 @@ $LIBCSRC/stdlib/getsubopt.c lib gpl # 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 @@ -144,6 +146,7 @@ $LIBCSRC/stdlib/getsubopt.c lib gpl # 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 @@ -160,6 +163,7 @@ $LIBCSRC/stdlib/getsubopt.c lib gpl # 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 diff --git a/lib/ChangeLog b/lib/ChangeLog index 451c64d52..9ec3d79dd 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,44 @@ +2005-09-01 Paul Eggert + + 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 * getdelim.c (getdelim): Return EOF on EOF. diff --git a/lib/regcomp.c b/lib/regcomp.c index 4ac78c351..dc9bbc102 100644 --- a/lib/regcomp.c +++ b/lib/regcomp.c @@ -50,7 +50,7 @@ static Idx search_duplicated_node (const re_dfa_t *dfa, Idx 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, - 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); @@ -81,7 +81,7 @@ static reg_errcode_t parse_bracket_element (bracket_elem_t *elem, 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); @@ -108,7 +108,7 @@ static bin_tree_t *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); static bin_tree_t *create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, re_token_type_t type); @@ -283,7 +283,7 @@ weak_alias (__re_compile_fastmap, re_compile_fastmap) 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) @@ -299,7 +299,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, { 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]; @@ -327,7 +327,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, &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 } @@ -382,7 +382,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, { 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); } } } @@ -1008,14 +1008,16 @@ static void 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) @@ -1031,7 +1033,7 @@ optimize_utf8 (re_dfa_t *dfa) } break; case OP_PERIOD: - has_period = 1; + has_period = true; break; case OP_BACK_REF: case OP_ALT: @@ -1398,7 +1400,7 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, 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;;) { @@ -1415,8 +1417,8 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_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) @@ -1441,9 +1443,9 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, /* ...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; } @@ -1452,8 +1454,8 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, 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 */ @@ -1471,8 +1473,8 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, 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); @@ -1483,8 +1485,8 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, { /* 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; } @@ -1492,8 +1494,8 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, 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; @@ -1544,7 +1546,7 @@ static reg_errcode_t 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); @@ -1553,8 +1555,8 @@ calc_inveclosure (re_dfa_t *dfa) 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; } } @@ -1568,11 +1570,11 @@ static reg_errcode_t 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) { @@ -1582,7 +1584,7 @@ calc_eclosure (re_dfa_t *dfa) { if (!incomplete) break; - incomplete = 0; + incomplete = false; node_idx = 0; } @@ -1594,13 +1596,13 @@ calc_eclosure (re_dfa_t *dfa) 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); } } @@ -1610,14 +1612,15 @@ calc_eclosure (re_dfa_t *dfa) /* 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; @@ -1651,14 +1654,14 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, int root) 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; } @@ -1670,13 +1673,15 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, int root) 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 @@ -2943,10 +2948,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, 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); @@ -2989,7 +2994,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, #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. */ @@ -3011,7 +3016,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *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; @@ -3022,7 +3028,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, *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); @@ -3051,15 +3057,15 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, 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; @@ -3229,7 +3235,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, 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; @@ -3482,7 +3488,7 @@ static bin_tree_t * 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 diff --git a/lib/regex_internal.c b/lib/regex_internal.c index bf3246105..702563f81 100644 --- a/lib/regex_internal.c +++ b/lib/regex_internal.c @@ -19,7 +19,7 @@ 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, @@ -37,7 +37,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, 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; @@ -65,7 +65,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_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)); @@ -161,14 +161,14 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) 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; @@ -1177,28 +1177,23 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) /* 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. */ @@ -1208,7 +1203,7 @@ re_node_set_insert (re_node_set *set, Idx elem) 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; } @@ -1229,14 +1224,14 @@ re_node_set_insert (re_node_set *set, Idx elem) /* 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) { @@ -1247,29 +1242,29 @@ 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. */ @@ -1482,7 +1477,11 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) { 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); diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 6a68058b7..3c17fc3c9 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -370,7 +371,7 @@ struct re_string_t 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; diff --git a/lib/regexec.c b/lib/regexec.c index 722193d57..257c64785 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -45,17 +45,17 @@ static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp, 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, @@ -71,7 +71,7 @@ static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, 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 @@ -91,10 +91,10 @@ static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx, 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; @@ -161,8 +161,8 @@ static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa, 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; @@ -175,8 +175,9 @@ static Idx 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, 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; /* Entry point for POSIX code. */ @@ -283,7 +284,7 @@ regoff_t 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) @@ -293,7 +294,8 @@ regoff_t 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) @@ -306,7 +308,7 @@ re_match_2 (struct re_pattern_buffer *bufp, 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) @@ -319,7 +321,7 @@ re_search_2 (struct re_pattern_buffer *bufp, 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) @@ -331,12 +333,12 @@ re_search_2_stub (struct re_pattern_buffer *bufp, 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; @@ -345,14 +347,13 @@ re_search_2_stub (struct re_pattern_buffer *bufp, 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; @@ -361,14 +362,13 @@ re_search_2_stub (struct re_pattern_buffer *bufp, 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 @@ -376,7 +376,7 @@ internal_function 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; @@ -614,10 +614,12 @@ re_search_internal (const regex_t *preg, 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 @@ -1058,7 +1060,7 @@ acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, 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; @@ -1067,7 +1069,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match, 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; @@ -1087,7 +1089,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match, 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; @@ -1157,7 +1159,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match, if (old_state == cur_state) next_start_idx = next_char_idx; else - at_init_state = 0; + at_init_state = false; } if (cur_state->halt) @@ -1188,19 +1190,19 @@ check_matching (re_match_context_t *mctx, int fl_longest_match, /* 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. @@ -1237,14 +1239,14 @@ proceed_next_node (const re_match_context_t *mctx, { 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. */ @@ -1305,8 +1307,8 @@ proceed_next_node (const re_match_context_t *mctx, 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, @@ -1380,7 +1382,7 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, 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; @@ -1388,7 +1390,7 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, 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); @@ -1417,7 +1419,7 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, 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); @@ -1651,7 +1653,7 @@ build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx, { 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; @@ -1683,8 +1685,8 @@ build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx, 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; } @@ -1866,7 +1868,7 @@ sub_epsilon_src_nodes (re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, 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) @@ -1897,9 +1899,9 @@ check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, if (src_pos == dst_pos) continue; /* This is unrelated limitation. */ else - return 1; + return true; } - return 0; + return false; } static int @@ -2135,7 +2137,8 @@ sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, 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) @@ -2161,8 +2164,8 @@ sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, } 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; @@ -3017,7 +3020,7 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, 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; @@ -3052,8 +3055,8 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, 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; @@ -3072,8 +3075,8 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, 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; @@ -3151,21 +3154,21 @@ check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes, 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; @@ -3243,14 +3246,14 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, 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; @@ -3275,17 +3278,18 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, } /* 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; @@ -3305,8 +3309,8 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) 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); @@ -3320,13 +3324,12 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) { 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); @@ -3351,9 +3354,9 @@ out_free: 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; @@ -3388,7 +3391,7 @@ out_free: 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); @@ -3488,7 +3491,7 @@ out_free: if (dests_node_malloced) free (dests_node); - return 1; + return true; } /* Group all nodes belonging to STATE into several destinations. @@ -3502,7 +3505,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, 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. */ @@ -3556,7 +3559,8 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, { 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); @@ -3616,7 +3620,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, 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)) @@ -3651,8 +3655,8 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, } /* 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. */ @@ -3947,7 +3951,8 @@ find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) 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; @@ -3959,7 +3964,7 @@ find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) 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; @@ -3984,7 +3989,7 @@ find_collation_sequence_value (const unsigned char *mbs, size_t 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) @@ -3995,28 +4000,28 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, { 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) @@ -4026,10 +4031,10 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, 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. */