Mercurial > hg > octave-lojdl > gnulib-hg
diff lib/regex_internal.c @ 6195:25eaa608fc4e
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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 01 Sep 2005 19:41:07 +0000 |
parents | 7a0537a5ad1b |
children | 49579c047f1d |
line wrap: on
line diff
--- 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 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 @@ 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 @@ 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 @@ /* 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 @@ 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 @@ /* 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 @@ 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 @@ { 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);