From a5bc2e013f419bae407a0bdc51c032674c46e275 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 27 Dec 2012 12:15:24 +0100 Subject: [PATCH] Fix non-typesafe/void * variant of GAVL to support non-unique keys. The original void * version of the gavl_insert() does not work correctly when insert mode with non-unique keys (GAVL_FAFTER) is requested. Bug reported by Rostislav Lisovy. Signed-off-by: Pavel Pisa --- ulut/ul_gavl.c | 2 +- ulut/ul_gavlchk.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ulut/ul_gavl.c b/ulut/ul_gavl.c index 20d4797..94cb319 100644 --- a/ulut/ul_gavl.c +++ b/ulut/ul_gavl.c @@ -121,7 +121,7 @@ gavl_search_node(const gavl_root_t *root, const void *key, break; } } - if(mode&GAVL_FAFTER){ + if((mode&GAVL_FAFTER)&&!(mode&GAVL_FCMP)){ if(cmp<=0) if(p) p=gavl_next_node(p); *nodep=p; diff --git a/ulut/ul_gavlchk.c b/ulut/ul_gavlchk.c index bb67226..66deb31 100644 --- a/ulut/ul_gavlchk.c +++ b/ulut/ul_gavlchk.c @@ -575,11 +575,12 @@ int main(int argc, char *argv[]) c=0; scanf("%c",&c); switch(c){ + case 'A': case 'a': if (scanf("%d",&val)==1){ item=malloc(sizeof(test_item1_t)); item->val=val; - ret=gavl_insert(&test_gavl1,item,0); + ret=gavl_insert(&test_gavl1,item,c == 'A'? GAVL_FAFTER: 0); printf("gavl_insert of val %d returned %d\n\n",val,ret); gavl_print_tree1(&test_gavl1, test_gavl1.root_node, 0, NULL, 0); } -- 2.39.2