From c091d47fc5be095afa3af04c6f358c4627ac1f50 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 21 Sep 2015 12:07:35 +0200 Subject: [PATCH] Fix own bregex implementation so that normal posix calls are allowed --- src/lib/bregex.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/lib/bregex.c b/src/lib/bregex.c index cebf599600f..d8fd0157959 100644 --- a/src/lib/bregex.c +++ b/src/lib/bregex.c @@ -1450,7 +1450,6 @@ var = (unsigned char)*text++; \ if (translate) \ var = translate[var] - int regcomp(regex_t * bufp, const char *regex, int cflags) { memset(bufp, 0, sizeof(regex_t)); @@ -1475,16 +1474,20 @@ void re_registers_to_regmatch(regexp_registers_t old_regs, regmatch_t pmatch[], size_t nmatch) { - size_t i=0; + if (!(nmatch == 0 && pmatch == NULL)) { + size_t i = 0; + + /* + * We have to set the last entry to -1 + */ + nmatch = nmatch - 1; + for (size_t i = 0; (i < nmatch) && (old_regs->start[i] > -1) ; i++) { + pmatch[i].rm_so = old_regs->start[i]; + pmatch[i].rm_eo = old_regs->end[i]; + } - /* We have to set the last entry to -1 */ - nmatch = nmatch - 1; - for (i=0; (i < nmatch) && (old_regs->start[i] > -1) ; i++) { - pmatch[i].rm_so = old_regs->start[i]; - pmatch[i].rm_eo = old_regs->end[i]; + pmatch[i].rm_eo = pmatch[i].rm_so = -1; } - - pmatch[i].rm_eo = pmatch[i].rm_so = -1; } int regexec(regex_t * preg, const char *string, size_t nmatch, @@ -1493,12 +1496,15 @@ int regexec(regex_t * preg, const char *string, size_t nmatch, int status; int len = strlen(string); struct re_registers regs; + status = re_search(preg, (unsigned char *)string, len, 0, len, ®s); if (status >= 0) { re_registers_to_regmatch(®s, pmatch, nmatch); } - /* status is the start position in the string base 0 where - * the pattern was found or negative if not found. + + /* + * status is the start position in the string base 0 where + * the pattern was found or negative if not found. */ return status < 0 ? -1 : 0; }