From 72c72010e12c96ee881dc5034913d6410af8f90b Mon Sep 17 00:00:00 2001 From: Christine Caulfield Date: Thu, 5 Mar 2020 09:41:52 +0000 Subject: [PATCH 1/3] trie: Don't assume that chars are unsigned < 126 Trie fails on systems with unsigned chars when using characters over 126. This needs looking over and running through the CI systems --- lib/trie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/trie.c b/lib/trie.c index 0e5dd6e4b..5b1f8b019 100644 --- a/lib/trie.c +++ b/lib/trie.c @@ -64,8 +64,8 @@ static void trie_destroy_node(struct trie_node *node); * characters are stored in reverse to make accessing the * more common case (non-control chars) more space efficient. */ -#define TRIE_CHAR2INDEX(ch) (126 - ch) -#define TRIE_INDEX2CHAR(idx) (126 - idx) +#define TRIE_CHAR2INDEX(ch) abs(126 - ch) +#define TRIE_INDEX2CHAR(idx) abs(126 - idx) static int32_t From aa80a88615c0a0e56a489b009601b5d18eed6c8d Mon Sep 17 00:00:00 2001 From: Christine Caulfield Date: Thu, 5 Mar 2020 13:44:17 +0000 Subject: [PATCH 2/3] test: Unit tests for high-characters in a map --- tests/check_map.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/check_map.c b/tests/check_map.c index e73c832ec..578e19bdf 100644 --- a/tests/check_map.c +++ b/tests/check_map.c @@ -41,6 +41,19 @@ const char *chars2[] = { NULL, }; +const char *composers[] = { + "Béla Bartók", + "Zoltán Kodály", + "Ludwig van Beethoven", + "Wolfgang Amadeus Mozart", + "Leoš Janáček", + "Benjamin Britten", + "Josef Haydn", + "Claude Debussy", + "Charles Ives" +}; + + static char *notified_key = NULL; static void *notified_value = NULL; static void *notified_new_value = NULL; @@ -717,6 +730,45 @@ test_map_load(qb_map_t *m, const char* test_name) qb_log(LOG_INFO, "%25s %12.2f dels/sec (%d/%fs)\n", test_name, ops, count2, secs); } +static void test_accents_load(qb_map_t *m, const char* test_name) +{ + int i; + int32_t res = 0; + int32_t count = 0; + int32_t count2; + void *value; + + ck_assert(m != NULL); + /* + * Load accented names + */ + for (i=0; i Date: Thu, 5 Mar 2020 15:42:37 +0000 Subject: [PATCH 3/3] trie: Some fixes and extra tests from Honza --- lib/trie.c | 4 ++-- tests/check_map.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/trie.c b/lib/trie.c index 5b1f8b019..0ecef6390 100644 --- a/lib/trie.c +++ b/lib/trie.c @@ -64,8 +64,8 @@ static void trie_destroy_node(struct trie_node *node); * characters are stored in reverse to make accessing the * more common case (non-control chars) more space efficient. */ -#define TRIE_CHAR2INDEX(ch) abs(126 - ch) -#define TRIE_INDEX2CHAR(idx) abs(126 - idx) +#define TRIE_CHAR2INDEX(ch) (127 - (signed char)ch) +#define TRIE_INDEX2CHAR(idx) (127 - (signed char)idx) static int32_t diff --git a/tests/check_map.c b/tests/check_map.c index 578e19bdf..5a98f757c 100644 --- a/tests/check_map.c +++ b/tests/check_map.c @@ -50,7 +50,9 @@ const char *composers[] = { "Benjamin Britten", "Josef Haydn", "Claude Debussy", - "Charles Ives" + "Charles Ives", + /* Maybe in an alien language ... but they can cause trie crashes & conflicts */ + "\x7e\x7f\x80\x81", "\x7e", "\x7e\x7f", "\x7e\x7f\x80", };