From 7cc84867ce73f03e7591cf00b313a05db196dda1 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 15:47:02 +0800 Subject: [PATCH] let slug_count returns -1 if error occurs --- src/node.c | 9 ++------- src/slug.c | 2 +- src/str.c | 1 + 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/node.c b/src/node.c index 16adc0c..3cdfb9d 100644 --- a/src/node.c +++ b/src/node.c @@ -571,13 +571,8 @@ node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route // common prefix not found, insert a new edge for this pattern if ( prefix_len == 0 ) { // there are two more slugs, we should break them into several parts - char *err = NULL; - int slug_cnt = slug_count(path, path_len, &err); - if (err) { - if(errstr) { - *errstr = err; - } - free(err); + int slug_cnt = slug_count(path, path_len, errstr); + if (slug_cnt == -1) { return NULL; } diff --git a/src/slug.c b/src/slug.c index 12cfd23..e3d2caa 100644 --- a/src/slug.c +++ b/src/slug.c @@ -172,7 +172,7 @@ int slug_count(const char * needle, int len, char **errstr) { if (errstr) { asprintf(errstr, "Incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state); } - return 0; + return -1; } return cnt; } diff --git a/src/str.c b/src/str.c index c38297a..190dd8d 100644 --- a/src/str.c +++ b/src/str.c @@ -11,6 +11,7 @@ #include #include "r3.h" #include "r3_str.h" +#include "slug.h" #include "zmalloc.h" int r3_pattern_to_opcode(const char * pattern, int len) {