-
- /* offset 0 is always '\0' */
- if (len == 0)
- return 0;
-
- /* descend root - start from last character of str */
- key = str[len - 1];
- node_idx = rules->trie_root[key];
- depth = 0;
-
- /* descend suffix trie */
- if (node_idx > 0) {
- while (1) {
- struct trie_node *node;
- unsigned int child_idx;
-
- node = &rules->trie_nodes[node_idx];
- depth++;
- off = node->value_off + node->value_len - len;
-
- /* match against current node */
- if (depth == len || (node->value_len >= len && memcmp(&rules->buf[off], str, len) == 0))
- return off;
-
- /* lookup child node */
- key = str[len - 1 - depth];
- child_idx = node->child_idx;
- while (child_idx > 0) {
- if (rules->trie_childs[child_idx].key == key)
- break;
- child_idx = rules->trie_childs[child_idx].next_idx;
- }
- if (child_idx == 0)
+ key = str[len-1];
+ node_idx = 0;
+ for (depth = 0; depth <= len; depth++) {
+ struct trie_node *node;
+ unsigned int child_idx;
+
+ node = &rules->trie_nodes[node_idx];
+ off = node->value_off + node->value_len - len;
+
+ /* match against current node */
+ if (depth == len || (node->value_len >= len && memcmp(&rules->buf[off], str, len) == 0))
+ return off;
+
+ /* lookup child node */
+ key = str[len - 1 - depth];
+ child_idx = node->child_idx;
+ while (child_idx > 0) {
+ struct trie_node *child;
+
+ child = &rules->trie_nodes[child_idx];
+ if (child->key == key)