Expansion safety
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 19 Jul 2010 16:57:30 +0000 (19:57 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 19 Jul 2010 16:59:31 +0000 (19:59 +0300)
include/vlc_arrays.h

index 390c1b6..b8dbae4 100644 (file)
@@ -48,7 +48,7 @@ static inline void *realloc_down( void *ptr, size_t size )
 #define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem )                           \
     do                                                                        \
     {                                                                         \
-        if( !i_oldsize ) (p_ar) = NULL;                                       \
+        if( !(i_oldsize) ) (p_ar) = NULL;                                       \
         (p_ar) = VLCCVP realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \
         if( !(p_ar) ) abort();                                                \
         if( (i_oldsize) - (i_pos) )                                           \
@@ -56,7 +56,7 @@ static inline void *realloc_down( void *ptr, size_t size )
             memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos),                  \
                      ((i_oldsize) - (i_pos)) * sizeof( *(p_ar) ) );           \
         }                                                                     \
-        (p_ar)[i_pos] = elem;                                                 \
+        (p_ar)[(i_pos)] = elem;                                                 \
         (i_oldsize)++;                                                        \
     }                                                                         \
     while( 0 )