Always set next correctly, even if a matching element is found (that is
[ffmpeg.git] / libavutil / tree.c
index f0a9145..6126ffa 100644 (file)
@@ -35,6 +35,10 @@ void *av_tree_find(const AVTreeNode *t, void *key, int (*cmp)(void *key, const v
             if(next) next[(v>>31)^1]= t->elem;
             return av_tree_find(t->child[v>>31], key, cmp, next);
         }else{
+            if(next){
+                av_tree_find(t->child[0], key, cmp, next);
+                av_tree_find(t->child[1], key, cmp, next);
+            }
             return t->elem;
         }
     }
@@ -132,9 +136,9 @@ int cmp(const void *a, const void *b){
     return a-b;
 }
 
-int main(){
+int main(void){
     int i,j,k;
-    AVTreeNode *root= av_mallocz(sizeof(AVTreeNode));
+    AVTreeNode *root= NULL;
 
     for(i=0; i<10000; i++){
         int j= (random()%863294);