let slug_count returns -1 if error occurs

This commit is contained in:
c9s 2014-06-02 15:47:02 +08:00
parent 2774221ab7
commit 7cc84867ce
3 changed files with 4 additions and 8 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -11,6 +11,7 @@
#include <assert.h>
#include "r3.h"
#include "r3_str.h"
#include "slug.h"
#include "zmalloc.h"
int r3_pattern_to_opcode(const char * pattern, int len) {