From 0f6506ab48115315e2762b59bba41b592884fdef Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 11 Sep 2008 14:36:03 +0200 Subject: [PATCH] Add protection against lookup in not compiled trie (and vice-versa). Signed-off-by: Florent Bruneau --- common/trie.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/trie.c b/common/trie.c index dc84236..9a04cf4 100644 --- a/common/trie.c +++ b/common/trie.c @@ -229,6 +229,7 @@ static inline void trie_entry_split(trie_t *trie, trie_entry_t *entry, int pos) void trie_insert(trie_t *trie, const char* key) { + assert(trie->entries == NULL && "Trie already compiled"); GROW(trie->keys, 1, trie->keys_len, trie->keys_size); trie->keys[trie->keys_len++] = strdup(key); } @@ -298,6 +299,8 @@ typedef char *str_t; void trie_compile(trie_t *trie, bool memlock) { + assert(trie->entries == NULL && "Trie already compiled"); + assert(trie->keys != NULL && "Trying to compile an empty trie"); { # define QSORT_TYPE str_t # define QSORT_BASE trie->keys @@ -318,6 +321,7 @@ void trie_compile(trie_t *trie, bool memlock) bool trie_lookup(const trie_t *trie, const char *key) { + assert(trie->keys == NULL && "Can't lookup: trie not compiled"); if (trie->entries_len == 0) { return false; } else { -- 2.20.1