diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-12-28 12:13:40 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-12-28 12:13:40 +0100 |
| commit | b0afb8fe0ff1d87165af9df61501197a06240dda (patch) | |
| tree | 274ac6a96c53ef4c19ab4974ce24a06a233128c5 /gl/regcomp.c | |
| parent | 68fc05381ee5fa0aee1413118fbb3d81ca888b09 (diff) | |
| download | monitoring-plugins-b0afb8fe0ff1d87165af9df61501197a06240dda.tar.gz | |
Sync with Gnulib stable-202507 code (a8ac9f9ce5)
Diffstat (limited to 'gl/regcomp.c')
| -rw-r--r-- | gl/regcomp.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/gl/regcomp.c b/gl/regcomp.c index 696cf813..878b65ba 100644 --- a/gl/regcomp.c +++ b/gl/regcomp.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
| 2 | Copyright (C) 2002-2024 Free Software Foundation, Inc. | 2 | Copyright (C) 2002-2025 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
| 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
| 5 | 5 | ||
| @@ -831,7 +831,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len) | |||
| 831 | if (table_size > pat_len) | 831 | if (table_size > pat_len) |
| 832 | break; | 832 | break; |
| 833 | 833 | ||
| 834 | dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size); | 834 | dfa->state_table = calloc (table_size, sizeof (struct re_state_table_entry)); |
| 835 | dfa->state_hash_mask = table_size - 1; | 835 | dfa->state_hash_mask = table_size - 1; |
| 836 | 836 | ||
| 837 | dfa->mb_cur_max = MB_CUR_MAX; | 837 | dfa->mb_cur_max = MB_CUR_MAX; |
| @@ -862,7 +862,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len) | |||
| 862 | { | 862 | { |
| 863 | int i, j, ch; | 863 | int i, j, ch; |
| 864 | 864 | ||
| 865 | dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); | 865 | dfa->sb_char = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t)); |
| 866 | if (__glibc_unlikely (dfa->sb_char == NULL)) | 866 | if (__glibc_unlikely (dfa->sb_char == NULL)) |
| 867 | return REG_ESPACE; | 867 | return REG_ESPACE; |
| 868 | 868 | ||
| @@ -1001,21 +1001,25 @@ create_initial_state (re_dfa_t *dfa) | |||
| 1001 | Idx dest_idx = dfa->edests[node_idx].elems[0]; | 1001 | Idx dest_idx = dfa->edests[node_idx].elems[0]; |
| 1002 | if (!re_node_set_contains (&init_nodes, dest_idx)) | 1002 | if (!re_node_set_contains (&init_nodes, dest_idx)) |
| 1003 | { | 1003 | { |
| 1004 | reg_errcode_t merge_err | 1004 | err |
| 1005 | = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx); | 1005 | = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx); |
| 1006 | if (merge_err != REG_NOERROR) | 1006 | if (err != REG_NOERROR) |
| 1007 | return merge_err; | 1007 | break; |
| 1008 | i = 0; | 1008 | i = 0; |
| 1009 | } | 1009 | } |
| 1010 | } | 1010 | } |
| 1011 | } | 1011 | } |
| 1012 | 1012 | ||
| 1013 | /* It must be the first time to invoke acquire_state. */ | 1013 | /* It must be the first time to invoke acquire_state. */ |
| 1014 | dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0); | 1014 | dfa->init_state |
| 1015 | /* We don't check ERR here, since the initial state must not be NULL. */ | 1015 | = (err == REG_NOERROR |
| 1016 | ? re_acquire_state_context (&err, dfa, &init_nodes, 0) | ||
| 1017 | : NULL); | ||
| 1016 | if (__glibc_unlikely (dfa->init_state == NULL)) | 1018 | if (__glibc_unlikely (dfa->init_state == NULL)) |
| 1017 | return err; | 1019 | { |
| 1018 | if (dfa->init_state->has_constraint) | 1020 | /* Don't check ERR here, as the initial state must not be null. */ |
| 1021 | } | ||
| 1022 | else if (dfa->init_state->has_constraint) | ||
| 1019 | { | 1023 | { |
| 1020 | dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes, | 1024 | dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes, |
| 1021 | CONTEXT_WORD); | 1025 | CONTEXT_WORD); |
| @@ -1025,17 +1029,13 @@ create_initial_state (re_dfa_t *dfa) | |||
| 1025 | &init_nodes, | 1029 | &init_nodes, |
| 1026 | CONTEXT_NEWLINE | 1030 | CONTEXT_NEWLINE |
| 1027 | | CONTEXT_BEGBUF); | 1031 | | CONTEXT_BEGBUF); |
| 1028 | if (__glibc_unlikely (dfa->init_state_word == NULL | ||
| 1029 | || dfa->init_state_nl == NULL | ||
| 1030 | || dfa->init_state_begbuf == NULL)) | ||
| 1031 | return err; | ||
| 1032 | } | 1032 | } |
| 1033 | else | 1033 | else |
| 1034 | dfa->init_state_word = dfa->init_state_nl | 1034 | dfa->init_state_word = dfa->init_state_nl |
| 1035 | = dfa->init_state_begbuf = dfa->init_state; | 1035 | = dfa->init_state_begbuf = dfa->init_state; |
| 1036 | 1036 | ||
| 1037 | re_node_set_free (&init_nodes); | 1037 | re_node_set_free (&init_nodes); |
| 1038 | return REG_NOERROR; | 1038 | return err; |
| 1039 | } | 1039 | } |
| 1040 | 1040 | ||
| 1041 | /* If it is possible to do searching in single byte encoding instead of UTF-8 | 1041 | /* If it is possible to do searching in single byte encoding instead of UTF-8 |
| @@ -1677,12 +1677,11 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) | |||
| 1677 | { | 1677 | { |
| 1678 | err = duplicate_node_closure (dfa, node, node, node, | 1678 | err = duplicate_node_closure (dfa, node, node, node, |
| 1679 | dfa->nodes[node].constraint); | 1679 | dfa->nodes[node].constraint); |
| 1680 | if (__glibc_unlikely (err != REG_NOERROR)) | ||
| 1681 | return err; | ||
| 1682 | } | 1680 | } |
| 1683 | 1681 | ||
| 1684 | /* Expand each epsilon destination nodes. */ | 1682 | /* Expand each epsilon destination nodes. */ |
| 1685 | if (IS_EPSILON_NODE(dfa->nodes[node].type)) | 1683 | if (__glibc_likely (err == REG_NOERROR) |
| 1684 | && IS_EPSILON_NODE (dfa->nodes[node].type)) | ||
| 1686 | for (i = 0; i < dfa->edests[node].nelem; ++i) | 1685 | for (i = 0; i < dfa->edests[node].nelem; ++i) |
| 1687 | { | 1686 | { |
| 1688 | re_node_set eclosure_elem; | 1687 | re_node_set eclosure_elem; |
| @@ -1700,14 +1699,14 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) | |||
| 1700 | { | 1699 | { |
| 1701 | err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false); | 1700 | err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false); |
| 1702 | if (__glibc_unlikely (err != REG_NOERROR)) | 1701 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1703 | return err; | 1702 | break; |
| 1704 | } | 1703 | } |
| 1705 | else | 1704 | else |
| 1706 | eclosure_elem = dfa->eclosures[edest]; | 1705 | eclosure_elem = dfa->eclosures[edest]; |
| 1707 | /* Merge the epsilon closure of 'edest'. */ | 1706 | /* Merge the epsilon closure of 'edest'. */ |
| 1708 | err = re_node_set_merge (&eclosure, &eclosure_elem); | 1707 | err = re_node_set_merge (&eclosure, &eclosure_elem); |
| 1709 | if (__glibc_unlikely (err != REG_NOERROR)) | 1708 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1710 | return err; | 1709 | break; |
| 1711 | /* If the epsilon closure of 'edest' is incomplete, | 1710 | /* If the epsilon closure of 'edest' is incomplete, |
| 1712 | the epsilon closure of this node is also incomplete. */ | 1711 | the epsilon closure of this node is also incomplete. */ |
| 1713 | if (dfa->eclosures[edest].nelem == 0) | 1712 | if (dfa->eclosures[edest].nelem == 0) |
| @@ -1717,12 +1716,18 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) | |||
| 1717 | } | 1716 | } |
| 1718 | } | 1717 | } |
| 1719 | 1718 | ||
| 1720 | if (incomplete && !root) | 1719 | if (err != REG_NOERROR) |
| 1721 | dfa->eclosures[node].nelem = 0; | 1720 | re_node_set_free (&eclosure); |
| 1722 | else | 1721 | else |
| 1723 | dfa->eclosures[node] = eclosure; | 1722 | { |
| 1724 | *new_set = eclosure; | 1723 | if (incomplete && !root) |
| 1725 | return REG_NOERROR; | 1724 | dfa->eclosures[node].nelem = 0; |
| 1725 | else | ||
| 1726 | dfa->eclosures[node] = eclosure; | ||
| 1727 | *new_set = eclosure; | ||
| 1728 | } | ||
| 1729 | |||
| 1730 | return err; | ||
| 1726 | } | 1731 | } |
| 1727 | 1732 | ||
| 1728 | /* Functions for token which are used in the parser. */ | 1733 | /* Functions for token which are used in the parser. */ |
| @@ -3055,8 +3060,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
| 3055 | _NL_COLLATE_SYMB_EXTRAMB); | 3060 | _NL_COLLATE_SYMB_EXTRAMB); |
| 3056 | } | 3061 | } |
| 3057 | #endif | 3062 | #endif |
| 3058 | sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); | 3063 | sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t)); |
| 3059 | mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); | 3064 | mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t)); |
| 3060 | if (__glibc_unlikely (sbcset == NULL || mbcset == NULL)) | 3065 | if (__glibc_unlikely (sbcset == NULL || mbcset == NULL)) |
| 3061 | { | 3066 | { |
| 3062 | re_free (sbcset); | 3067 | re_free (sbcset); |
| @@ -3275,6 +3280,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
| 3275 | else | 3280 | else |
| 3276 | { | 3281 | { |
| 3277 | free_charset (mbcset); | 3282 | free_charset (mbcset); |
| 3283 | mbcset = NULL; | ||
| 3278 | /* Build a tree for simple bracket. */ | 3284 | /* Build a tree for simple bracket. */ |
| 3279 | br_token.type = SIMPLE_BRACKET; | 3285 | br_token.type = SIMPLE_BRACKET; |
| 3280 | br_token.opr.sbcset = sbcset; | 3286 | br_token.opr.sbcset = sbcset; |
| @@ -3288,7 +3294,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
| 3288 | *err = REG_ESPACE; | 3294 | *err = REG_ESPACE; |
| 3289 | parse_bracket_exp_free_return: | 3295 | parse_bracket_exp_free_return: |
| 3290 | re_free (sbcset); | 3296 | re_free (sbcset); |
| 3291 | free_charset (mbcset); | 3297 | if (__glibc_likely (mbcset != NULL)) |
| 3298 | free_charset (mbcset); | ||
| 3292 | return NULL; | 3299 | return NULL; |
| 3293 | } | 3300 | } |
| 3294 | 3301 | ||
| @@ -3548,13 +3555,13 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans, | |||
| 3548 | reg_errcode_t ret; | 3555 | reg_errcode_t ret; |
| 3549 | bin_tree_t *tree; | 3556 | bin_tree_t *tree; |
| 3550 | 3557 | ||
| 3551 | sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); | 3558 | sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t)); |
| 3552 | if (__glibc_unlikely (sbcset == NULL)) | 3559 | if (__glibc_unlikely (sbcset == NULL)) |
| 3553 | { | 3560 | { |
| 3554 | *err = REG_ESPACE; | 3561 | *err = REG_ESPACE; |
| 3555 | return NULL; | 3562 | return NULL; |
| 3556 | } | 3563 | } |
| 3557 | mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); | 3564 | mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t)); |
| 3558 | if (__glibc_unlikely (mbcset == NULL)) | 3565 | if (__glibc_unlikely (mbcset == NULL)) |
| 3559 | { | 3566 | { |
| 3560 | re_free (sbcset); | 3567 | re_free (sbcset); |
