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
6ec17247
Commit
6ec17247
authored
Apr 16, 2012
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
block: add some built-in sanity checks
parent
868b0869
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
+37
-2
src/misc/block.c
src/misc/block.c
+37
-2
No files found.
src/misc/block.c
View file @
6ec17247
...
...
@@ -48,6 +48,36 @@ static void BlockNoRelease( block_t *b )
fprintf
(
stderr
,
"block %p has no release callback! This is a bug!
\n
"
,
b
);
abort
();
}
static
void
block_Check
(
block_t
*
block
)
{
while
(
block
!=
NULL
)
{
unsigned
char
*
start
=
block
->
p_start
;
unsigned
char
*
end
=
block
->
p_start
+
block
->
i_size
;
unsigned
char
*
bufstart
=
block
->
p_buffer
;
unsigned
char
*
bufend
=
block
->
p_buffer
+
block
->
i_buffer
;
assert
(
block
->
pf_release
!=
BlockNoRelease
);
assert
(
start
<=
end
);
assert
(
bufstart
<=
bufend
);
assert
(
bufstart
>=
start
);
assert
(
bufend
<=
end
);
block
=
block
->
p_next
;
}
}
static
void
block_Invalidate
(
block_t
*
block
)
{
block
->
p_next
=
NULL
;
block_Check
(
block
);
block
->
pf_release
=
BlockNoRelease
;
barrier
();
/* prevent compiler from optimizing this assignment out */
}
#else
# define block_Check(b) ((void)(b))
# define block_Invalidate(b) ((void)(b))
#endif
void
block_Init
(
block_t
*
restrict
b
,
void
*
buf
,
size_t
size
)
...
...
@@ -68,9 +98,10 @@ void block_Init( block_t *restrict b, void *buf, size_t size )
#endif
}
static
void
BlockRelease
(
block_t
*
p_block
)
static
void
BlockRelease
(
block_t
*
block
)
{
free
(
p_block
);
block_Invalidate
(
block
);
free
(
block
);
}
static
void
BlockMetaCopy
(
block_t
*
restrict
out
,
const
block_t
*
in
)
...
...
@@ -116,6 +147,8 @@ block_t *block_Realloc( block_t *p_block, ssize_t i_prebody, size_t i_body )
{
size_t
requested
=
i_prebody
+
i_body
;
block_Check
(
p_block
);
/* Corner case: empty block requested */
if
(
i_prebody
<=
0
&&
i_body
<=
(
size_t
)(
-
i_prebody
)
)
{
...
...
@@ -225,6 +258,7 @@ block_t *block_Realloc( block_t *p_block, ssize_t i_prebody, size_t i_body )
static
void
block_heap_Release
(
block_t
*
block
)
{
block_Invalidate
(
block
);
free
(
block
->
p_start
);
free
(
block
);
}
...
...
@@ -260,6 +294,7 @@ block_t *block_heap_Alloc (void *addr, size_t length)
static
void
block_mmap_Release
(
block_t
*
block
)
{
block_Invalidate
(
block
);
munmap
(
block
->
p_start
,
block
->
i_size
);
free
(
block
);
}
...
...
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