mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-19 22:05:58 +00:00
buffer: Fix gst_buffer_memcmp() where the buffer is smaller than size
Also add unit tests for gst_buffer_memcmp https://bugzilla.gnome.org/show_bug.cgi?id=706162
This commit is contained in:
parent
bd2ece0c48
commit
f90f3cde5f
2 changed files with 31 additions and 0 deletions
|
@ -1685,6 +1685,9 @@ gst_buffer_memcmp (GstBuffer * buffer, gsize offset, gconstpointer mem,
|
|||
"buffer %p, offset %" G_GSIZE_FORMAT ", size %" G_GSIZE_FORMAT, buffer,
|
||||
offset, size);
|
||||
|
||||
if (G_UNLIKELY (gst_buffer_get_size (buffer) < offset + size))
|
||||
return -1;
|
||||
|
||||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
|
||||
for (i = 0; i < len && size > 0 && res == 0; i++) {
|
||||
|
|
|
@ -294,6 +294,33 @@ GST_START_TEST (test_metadata_writable)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_memcmp)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
char buf[3] = { 0, 0, 0 };
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (2);
|
||||
gst_buffer_memset (buffer, 0, 0, 2);
|
||||
|
||||
fail_unless (gst_buffer_memcmp (buffer, 0, buf, 2) == 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 0, buf, 1) == 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 1, buf, 1) == 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 0, buf, 3) != 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 2, buf, 1) != 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 4, buf, 1) != 0);
|
||||
|
||||
gst_buffer_memset (buffer, 0, 0x20, 2);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 0, buf, 2) != 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 0, buf, 1) != 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 1, buf, 1) != 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 0, buf, 3) != 0);
|
||||
fail_unless (gst_buffer_memcmp (buffer, 2, buf, 1) != 0);
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_copy)
|
||||
{
|
||||
GstBuffer *buffer, *copy;
|
||||
|
@ -842,6 +869,7 @@ gst_buffer_suite (void)
|
|||
tcase_add_test (tc_chain, test_make_writable);
|
||||
tcase_add_test (tc_chain, test_span);
|
||||
tcase_add_test (tc_chain, test_metadata_writable);
|
||||
tcase_add_test (tc_chain, test_memcmp);
|
||||
tcase_add_test (tc_chain, test_copy);
|
||||
tcase_add_test (tc_chain, test_try_new_and_alloc);
|
||||
tcase_add_test (tc_chain, test_size);
|
||||
|
|
Loading…
Reference in a new issue