2003-09-20 Paolo Bonzini * posix/regcomp.c (peek_token): don't look back for ( or | to check whether to treat a caret as special. It fails for the (extended) regex \(^. (parse, parse_reg_exp): pass RE_CARET_ANCHORS_HERE to fetch_token. * include/regex.h: define RE_CARET_ANCHORS_HERE. * posix/regexec.c: check out of bounds value before shifting. diff -up save/regcomp.c ./regcomp.c --- save/regcomp.c 2003-09-20 14:37:45.000000000 +0200 +++ ./regcomp.c 2003-09-20 14:53:25.000000000 +0200 @@ -1650,12 +1650,11 @@ peek_token (token, input, syntax) token->type = OP_PERIOD; break; case '^': - if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) && + if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) && re_string_cur_idx (input) != 0) { char prev = re_string_peek_byte (input, -1); - if (prev != '|' && prev != '(' && - (!(syntax & RE_NEWLINE_ALT) || prev != '\n')) + if (!(syntax & RE_NEWLINE_ALT) || prev != '\n') break; } token->type = ANCHOR; @@ -1790,7 +1789,7 @@ parse (regexp, preg, syntax, err) bin_tree_t *tree, *eor, *root; re_token_t current_token; int new_idx; - current_token = fetch_token (regexp, syntax); + current_token = fetch_token (regexp, syntax | RE_CARET_ANCHORS_HERE); tree = parse_reg_exp (regexp, preg, ¤t_token, syntax, 0, err); if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; @@ -1837,7 +1836,7 @@ parse_reg_exp (regexp, preg, token, synt { re_token_t alt_token = *token; new_idx = re_dfa_add_node (dfa, alt_token, 0); - *token = fetch_token (regexp, syntax); + *token = fetch_token (regexp, syntax | RE_CARET_ANCHORS_HERE); if (token->type != OP_ALT && token->type != END_OF_RE && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) { diff -up save/regex.h ./regex.h --- save/regex.h 2003-09-20 14:26:46.000000000 +0200 +++ ./regex.h 2003-09-20 14:53:08.000000000 +0200 @@ -168,6 +168,11 @@ typedef unsigned long int reg_syntax_t; If not set, then case is significant. */ #define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) +/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only + for ^, because it is difficult to scan the regex backwards to find + whether ^ should be special. */ +#define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) + /* This global variable defines the particular regexp syntax to use (for some interfaces). When a regexp is compiled, the syntax used is stored in the pattern buffer, so changing this does not affect diff -up save/regex_internal.h ./regex_internal.h --- save/regex_internal.h 2003-09-20 14:32:42.000000000 +0200 +++ ./regex_internal.h 2003-09-20 14:33:47.000000000 +0200 @@ -102,9 +102,16 @@ # define __iswctype iswctype # define __btowc btowc # define __mempcpy memcpy +# define __wcrtomb wcrtomb # define attribute_hidden #endif /* not _LIBC */ +#ifdef __GNUC__ +#define __attribute __attribute__ +#else +#define __attribute +#endif + extern const char __re_error_msgid[] attribute_hidden; extern const size_t __re_error_msgid_idx[] attribute_hidden; diff -up save/regexec.c ./regexec.c --- save/regexec.c 2003-09-20 14:29:33.000000000 +0200 +++ ./regexec.c 2003-09-20 14:31:13.000000000 +0200 @@ -2194,6 +2194,7 @@ check_subexp_matching_top (dfa, mctx, cu { int node = cur_nodes->elems[node_idx]; if (dfa->nodes[node].type == OP_OPEN_SUBEXP + && dfa->nodes[node].opr.idx < (8 * sizeof (dfa->used_bkref_map)) && dfa->used_bkref_map & (1 << dfa->nodes[node].opr.idx)) { err = match_ctx_add_subtop (mctx, node, str_idx);