[SCM] libav/experimental: Avoid undefined behavior for removing elements that were not in the tree.

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:30:21 UTC 2013


The following commit has been merged in the experimental branch:
commit eed36075645ecc3d3ef202c94badb66818114c2c
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Fri Sep 19 12:41:12 2008 +0000

    Avoid undefined behavior for removing elements that were not in the tree.
    
    Originally committed as revision 15368 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavutil/tree.c b/libavutil/tree.c
index cb442ff..64653aa 100644
--- a/libavutil/tree.c
+++ b/libavutil/tree.c
@@ -119,8 +119,11 @@ void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const voi
         return ret;
     }else{
         *tp= *next; *next= NULL;
-        (*tp)->elem= key;
-        return NULL;
+        if(*tp){
+            (*tp)->elem= key;
+            return NULL;
+        }else
+            return key;
     }
 }
 
@@ -188,8 +191,7 @@ int main(void){
         av_tree_insert(&root, (void*)(j+1), cmp, &node);
 
         j= (random()%86294);
-        k= av_tree_find(root, (void*)(j+1), cmp, NULL);
-        if(k){
+        {
             AVTreeNode *node2=NULL;
             av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j);
             av_tree_insert(&root, (void*)(j+1), cmp, &node2);
diff --git a/libavutil/tree.h b/libavutil/tree.h
index c457234..ed6611c 100644
--- a/libavutil/tree.h
+++ b/libavutil/tree.h
@@ -45,8 +45,7 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *ke
 
 /**
  * Inserts or removes an element.
- * If *next is NULL then the element supplied will be removed, if no such
- * element exists behavior is undefined.
+ * If *next is NULL then the element supplied will be removed if it exists.
  * If *next is not NULL then the element supplied will be inserted, unless
  * it already exists in the tree.
  * @param rootp A pointer to a pointer to the root node of the tree. Note that

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list