pike.git / src / modules / Regexp / pike_regexp.c

version» Context lines:

pike.git/src/modules/Regexp/pike_regexp.c:242:    *    * Beware that the optimization-preparation code in here knows about some    * of the structure of the compiled regexp.    */   regexp *pike_regcomp(const char *exp)   {    regexp *r = NULL;    char *scan;    int flags;    short *exp2,*dest,c; +  ONERROR oerr;       if (exp == NULL)    FAIL("NULL argument");       exp2=xcalloc( (strlen(exp)+1), sizeof(short) ); -  +  SET_ONERROR(oerr, free, exp2);    for ( dest=exp2; (c=UCHARAT(exp++)); ) {    switch (c) {    case '(':    case ')':    case '.':    case '*':    case '+':    case '|':    case '$':    case '^':
pike.git/src/modules/Regexp/pike_regexp.c:297:    regparse = exp2;    regnpar = 1;    regsize = 0L;    regcode = regdummy;    if (reg(0, &flags) == NULL)    goto exit_regcomp;       /* Small enough for pointer-storage convention? */    if (regsize >= 32767L) /* Probably could be 65535L. */    { -  free(exp2); +     FAIL("regexp too big");    }       /* Allocate space. */ -  r = malloc(sizeof(regexp) + (unsigned) regsize); -  if(!r) -  { -  free(exp2); -  Pike_error(msg_out_of_mem); -  } +  r = xalloc(sizeof(regexp) + (unsigned) regsize);       /* Second pass: emit code. */    regparse = exp2;    regnpar = 1;    regcode = r->program;    if (reg(0, &flags) == NULL)    {    free(r);    r = NULL;    goto exit_regcomp;
pike.git/src/modules/Regexp/pike_regexp.c:358:    strlen(OPERAND(scan)) >= (size_t)len) {    longest = OPERAND(scan);    len = strlen(OPERAND(scan));    }    r->regmust = longest;    r->regmlen = len;    }    }       exit_regcomp: -  free(exp2); +  CALL_AND_UNSET_ONERROR(oerr);    return r;   }      /*    - reg - regular expression, i.e. main body or parenthesized thing    *    * Caller must absorb opening parenthesis.    *    * Combining parenthesis handling with the base level of regular    * expression is a trifle forced, but the need to tie the tails of the