Chris Card wrote:
>>>>> Looking at the code in sssvlv.c, it uses tavl_find3() to search the
values, but the
>>>>> code in tavl_find3() looks to me that it only works properly with an
exact match
>>>>> type of matching rule:
>>>>>
>>>>> Avlnode *
>>>>> tavl_find3( Avlnode *root, const void *data, AVL_CMP fcmp, int *ret
)
>>>>> {
>>>>> int cmp = -1, dir;
>>>>> Avlnode *prev = root;
>>>>>
>>>>> while ( root != 0&& (cmp = (*fcmp)( data, root->avl_data
)) != 0 ) {
>>>>> prev = root;
>>>>> dir = cmp> 0;
>>>>> root = avl_child( root, dir );
>>>>> }
>>>>> *ret = cmp;
>>>>> return root ? root : prev;
>>>>> }
>>>>>
>>>>> since the while loop terminates when the fcmp function returns 0
(i.e. exact match).
>>>>>
>>>>
>>>> I think I've worked out where the problem is.
>>>> Firstly, there's a comment before tavl_find3() saying
>>>> /*
>>>> * tavl_find2 - returns Avlnode instead of data pointer.
>>>> * tavl_find3 - as above, but returns Avlnode even if no match is found.
>>>> * also set *ret = last comparison result, or -1 if root == NULL.
>>>> */
>>>>
>>>> but the "or -1 if root == NULL" is not done.
>
> Not true; since cmp is initialized to -1, it will return -1 when the function
> is entered with root == NULL. There is no bug in this part.It depends how you read
the comment.
I wrote the code and the comment; it does what I intended it to do. There is
no "depends" about it.
--
-- Howard Chu
CTO, Symas Corp.
http://www.symas.com
Director, Highland Sun
http://highlandsun.com/hyc/
Chief Architect, OpenLDAP
http://www.openldap.org/project/