Browse Source

* src/filters/preg.c : append() refactoring

master
Alex 'AdUser' Z 4 years ago
parent
commit
e8e50b4b4b
  1. 17
      src/filters/preg.c

17
src/filters/preg.c

@ -95,7 +95,14 @@ append(cfg_t *cfg, const char *pattern) {
if ((regex = calloc(1, sizeof(rx_t))) == NULL) if ((regex = calloc(1, sizeof(rx_t))) == NULL)
return false; return false;
if ((ret = regcomp(&regex->regex, buf, flags)) == 0) { if ((ret = regcomp(&regex->regex, buf, flags)) != 0) {
char buf[256] = "";
regerror(ret, &regex->regex, buf, sizeof(buf));
log_msg(cfg, error, "regex compile error: %s", buf);
free(regex);
return false;
}
regex->score = cfg->defscore; regex->score = cfg->defscore;
regex->ftag = fnv_32a_str(pattern, FNV1_32A_INIT); regex->ftag = fnv_32a_str(pattern, FNV1_32A_INIT);
strlcpy(regex->pattern, pattern, sizeof(regex->pattern)); strlcpy(regex->pattern, pattern, sizeof(regex->pattern));
@ -108,14 +115,6 @@ append(cfg_t *cfg, const char *pattern) {
cfg->rlast = regex; cfg->rlast = regex;
cfg->flags |= MOD_IS_READY; cfg->flags |= MOD_IS_READY;
return true; return true;
} else {
char buf[256] = "";
regerror(ret, &regex->regex, buf, sizeof(buf));
log_msg(cfg, error, "regex compile error: %s", buf);
}
free(regex);
return false;
} }
uint32_t uint32_t

Loading…
Cancel
Save