diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2008-09-19 12:41:12 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2008-09-19 12:41:12 +0000 |
commit | eed36075645ecc3d3ef202c94badb66818114c2c (patch) | |
tree | 8fc00002f9f328d58280c7ca2590a64cce8b8961 /libavutil/tree.c | |
parent | 0354ddb71c18ea8e9d05d6d2509f9ec786a4488d (diff) | |
download | ffmpeg-eed36075645ecc3d3ef202c94badb66818114c2c.tar.gz |
Avoid undefined behavior for removing elements that were not in the tree.
Originally committed as revision 15368 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil/tree.c')
-rw-r--r-- | libavutil/tree.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libavutil/tree.c b/libavutil/tree.c index cb442ff4b0..64653aaccb 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); |