[vlc-devel] [PATCH] INSERT_ELEM macro: assert arguments validity

Rafaël Carré rafael.carre at gmail.com
Sun Jun 13 21:01:28 CEST 2010


Assertion message shows the arguments and file/line from the file where
the macro is used, not from the header.

Tested on gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
---
 include/vlc_arrays.h |    3 +++
 src/playlist/tree.c  |    1 -
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
index 390c1b6..3f91e11 100644
--- a/include/vlc_arrays.h
+++ b/include/vlc_arrays.h
@@ -25,6 +25,8 @@
 #ifndef VLC_ARRAYS_H_
 #define VLC_ARRAYS_H_
 
+#include <assert.h>
+
 /**
  * \file
  * This file defines functions, structures and macros for handling arrays in vlc
@@ -48,6 +50,7 @@ static inline void *realloc_down( void *ptr, size_t size )
 #define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem )                           \
     do                                                                        \
     {                                                                         \
+        assert( i_pos <= i_oldsize );                                         \
         if( !i_oldsize ) (p_ar) = NULL;                                       \
         (p_ar) = VLCCVP realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \
         if( !(p_ar) ) abort();                                                \
diff --git a/src/playlist/tree.c b/src/playlist/tree.c
index dff0a73..e7fdebe 100644
--- a/src/playlist/tree.c
+++ b/src/playlist/tree.c
@@ -208,7 +208,6 @@ int playlist_NodeInsert( playlist_t *p_playlist,
    (void)p_playlist;
    assert( p_parent && p_parent->i_children != -1 );
    if( i_position == -1 ) i_position = p_parent->i_children ;
-   assert( i_position <= p_parent->i_children);
 
    INSERT_ELEM( p_parent->pp_children,
                 p_parent->i_children,
-- 
1.7.0.4





More information about the vlc-devel mailing list