[vlc-devel] [PATCH 2/2] block: do not allow negative discard values in blocks
Steve Lhomme
robux4 at ycbcr.xyz
Fri Apr 2 13:46:11 UTC 2021
This feature is never used and negative ssize_t is supposed to be only -1:
https://pubs.opengroup.org/onlinepubs/007908775/xsh/systypes.h.html
The type ssize_t is capable of storing values at least in the range
[-1, SSIZE_MAX]
---
include/vlc_block.h | 9 ++++-----
src/misc/block.c | 4 ++--
src/test/block_test.c | 5 -----
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/vlc_block.h b/include/vlc_block.h
index 1acf4aa9250..4600eeb2fef 100644
--- a/include/vlc_block.h
+++ b/include/vlc_block.h
@@ -163,7 +163,7 @@ VLC_API block_t *block_Init(block_t *block,
*/
VLC_API block_t *block_Alloc(size_t size) VLC_USED VLC_MALLOC;
-VLC_API block_t *block_TryRealloc(block_t *, ssize_t pre, size_t body) VLC_USED;
+VLC_API block_t *block_TryRealloc(block_t *, size_t pre, size_t body) VLC_USED;
/**
* Reallocates a block.
@@ -173,11 +173,10 @@ VLC_API block_t *block_TryRealloc(block_t *, ssize_t pre, size_t body) VLC_USED;
* reusing spare buffer space. Otherwise, a new block is created and data is
* copied.
*
- * @param pre count of bytes to prepend if positive,
- * count of leading bytes to discard if negative
+ * @param pre count of bytes to prepend
* @param body new bytes size of the block
*
- * @return the reallocated block on succes, NULL on error.
+ * @return the reallocated block on success, NULL on error.
*
* @note Skipping leading bytes can be achieved directly by subtracting from
* block_t.i_buffer and adding block_t.p_buffer.
@@ -186,7 +185,7 @@ VLC_API block_t *block_TryRealloc(block_t *, ssize_t pre, size_t body) VLC_USED;
* @note On error, the block is discarded.
* To avoid that, use block_TryRealloc() instead.
*/
-VLC_API block_t *block_Realloc(block_t *, ssize_t pre, size_t body) VLC_USED;
+VLC_API block_t *block_Realloc(block_t *, size_t pre, size_t body) VLC_USED;
/**
* Releases a block.
diff --git a/src/misc/block.c b/src/misc/block.c
index 74da567145c..c527ed4f6b3 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -141,7 +141,7 @@ void block_Release(block_t *block)
block->cbs->free(block);
}
-block_t *block_TryRealloc (block_t *p_block, ssize_t i_prebody, size_t i_body)
+block_t *block_TryRealloc (block_t *p_block, size_t i_prebody, size_t i_body)
{
block_Check( p_block );
@@ -232,7 +232,7 @@ block_t *block_TryRealloc (block_t *p_block, ssize_t i_prebody, size_t i_body)
return p_block;
}
-block_t *block_Realloc (block_t *block, ssize_t prebody, size_t body)
+block_t *block_Realloc (block_t *block, size_t prebody, size_t body)
{
block_t *rea = block_TryRealloc (block, prebody, body);
if (rea == NULL)
diff --git a/src/test/block_test.c b/src/test/block_test.c
index 5c1a6b00d30..5c624458129 100644
--- a/src/test/block_test.c
+++ b/src/test/block_test.c
@@ -75,11 +75,6 @@ static void test_block (void)
assert (block != NULL);
assert (block->i_buffer == 200 + sizeof (text) + 200);
assert (!memcmp (block->p_buffer + 200, text, sizeof (text)));
-
- block = block_Realloc (block, -200, sizeof (text) + 200);
- assert (block != NULL);
- assert (block->i_buffer == sizeof (text));
- assert (!memcmp (block->p_buffer, text, sizeof (text)));
block_Release (block);
//block = block_Alloc (SIZE_MAX);
--
2.29.2
More information about the vlc-devel
mailing list