MCPcopy Create free account
hub / github.com/git/git / re_compile_internal

Function re_compile_internal

compat/regex/regcomp.c:749–843  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
754static reg_errcode_t
755re_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 (&regexp, pattern, length, preg->translate,
804 syntax & RE_ICASE, dfa);
805 if (BE (err != REG_NOERROR, 0))
806 {

Callers 3

re_compile_patternFunction · 0.85
regcompFunction · 0.85
re_compFunction · 0.85

Calls 9

init_dfaFunction · 0.85
free_dfa_contentFunction · 0.85
re_string_constructFunction · 0.85
free_workarea_compileFunction · 0.85
re_string_destructFunction · 0.85
parseFunction · 0.85
analyzeFunction · 0.85
optimize_utf8Function · 0.85
create_initial_stateFunction · 0.85

Tested by

no test coverage detected