Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
982400e1
Commit
982400e1
authored
May 24, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error-proof REMOVE_ELEM
parent
90daa759
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
include/vlc_arrays.h
include/vlc_arrays.h
+13
-8
No files found.
include/vlc_arrays.h
View file @
982400e1
...
@@ -30,6 +30,13 @@
...
@@ -30,6 +30,13 @@
* This file defines functions, structures and macros for handling arrays in vlc
* This file defines functions, structures and macros for handling arrays in vlc
*/
*/
/* realloc() that never fails *if* downsizing */
static
inline
void
*
realloc_down
(
void
*
ptr
,
size_t
size
)
{
void
*
ret
=
realloc
(
ptr
,
size
);
return
ret
?
ret
:
ptr
;
}
/**
/**
* Simple dynamic array handling. Array is realloced at each insert/removal
* Simple dynamic array handling. Array is realloced at each insert/removal
*/
*/
...
@@ -53,25 +60,23 @@
...
@@ -53,25 +60,23 @@
} \
} \
while( 0 )
while( 0 )
#define REMOVE_ELEM( p_ar, i_
oldsize, i_pos )
\
#define REMOVE_ELEM( p_ar, i_
size, i_pos )
\
do \
do \
{ \
{ \
if( (i_
oldsize) - (i_pos) - 1 )
\
if( (i_
size) - (i_pos) - 1 )
\
{ \
{ \
memmove( (p_ar) + (i_pos), \
memmove( (p_ar) + (i_pos), \
(p_ar) + (i_pos) + 1, \
(p_ar) + (i_pos) + 1, \
((i_oldsize) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \
((i_size) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \
} \
if( i_oldsize > 1 ) \
{ \
(p_ar) = realloc( p_ar, ((i_oldsize) - 1) * sizeof( *(p_ar) ) ); \
} \
} \
if( i_size > 1 ) \
(p_ar) = realloc_down( p_ar, ((i_size) - 1) * sizeof( *(p_ar) ) );\
else \
else \
{ \
{ \
free( p_ar ); \
free( p_ar ); \
(p_ar) = NULL; \
(p_ar) = NULL; \
} \
} \
(i_
oldsize)--;
\
(i_
size)--;
\
} \
} \
while( 0 )
while( 0 )
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment