| 747 | #endif /* _REGEX_RE_COMP */ |
| 748 | |
| 749 | |
| 750 | /* Internal entry point. |
| 751 | Compile the regular expression PATTERN, whose length is LENGTH. |
| 752 | SYNTAX indicate regular expression's syntax. */ |
| 753 | |
| 754 | static reg_errcode_t |
| 755 | re_compile_internal (regex_t *preg, const char * pattern, size_t length, |
| 756 | reg_syntax_t syntax) |
| 757 | { |
| 758 | reg_errcode_t err = REG_NOERROR; |
| 759 | re_dfa_t *dfa; |
| 760 | re_string_t regexp; |
| 761 | |
| 762 | /* Initialize the pattern buffer. */ |
| 763 | preg->fastmap_accurate = 0; |
| 764 | preg->syntax = syntax; |
| 765 | preg->not_bol = preg->not_eol = 0; |
| 766 | preg->used = 0; |
| 767 | preg->re_nsub = 0; |
| 768 | preg->can_be_null = 0; |
| 769 | preg->regs_allocated = REGS_UNALLOCATED; |
| 770 | |
| 771 | /* Initialize the dfa. */ |
| 772 | dfa = (re_dfa_t *) preg->buffer; |
| 773 | if (BE (preg->allocated < sizeof (re_dfa_t), 0)) |
| 774 | { |
| 775 | /* If zero allocated, but buffer is non-null, try to realloc |
| 776 | enough space. This loses if buffer's address is bogus, but |
| 777 | that is the user's responsibility. If ->buffer is NULL this |
| 778 | is a simple allocation. */ |
| 779 | dfa = re_realloc (preg->buffer, re_dfa_t, 1); |
| 780 | if (dfa == NULL) |
| 781 | return REG_ESPACE; |
| 782 | preg->allocated = sizeof (re_dfa_t); |
| 783 | preg->buffer = (unsigned char *) dfa; |
| 784 | } |
| 785 | preg->used = sizeof (re_dfa_t); |
| 786 | |
| 787 | err = init_dfa (dfa, length); |
| 788 | if (BE (err != REG_NOERROR, 0)) |
| 789 | { |
| 790 | free_dfa_content (dfa); |
| 791 | preg->buffer = NULL; |
| 792 | preg->allocated = 0; |
| 793 | return err; |
| 794 | } |
| 795 | #ifdef DEBUG |
| 796 | /* Note: length+1 will not overflow since it is checked in init_dfa. */ |
| 797 | dfa->re_str = re_malloc (char, length + 1); |
| 798 | strncpy (dfa->re_str, pattern, length + 1); |
| 799 | #endif |
| 800 | |
| 801 | __libc_lock_init (dfa->lock); |
| 802 | |
| 803 | err = re_string_construct (®exp, pattern, length, preg->translate, |
| 804 | syntax & RE_ICASE, dfa); |
| 805 | if (BE (err != REG_NOERROR, 0)) |
| 806 | { |
no test coverage detected