Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/GStreamer/gstreamer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Nazar <nazard@nazar.ca>2021-04-23 19:12:58 +0300
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-06-08 10:59:05 +0300
commitb16e96dd878e0c5e7baeb8fad62ca43de1f66982 (patch)
tree6c47561dd9f8f59138a22b7fe2931825475edfb6
parent4c75ec53e7b850fe3845e4fd981a59c9e103287c (diff)
Use g_memdup2() where available and add fallback for older GLib versions
glib 2.68 deprecates g_memdup(). Replace with g_memdup2() and add fallback if compiling against older versions, since we want to avoid deprecation warnings. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/803>
-rw-r--r--gst/glib-compat-private.h3
-rw-r--r--gst/gstregistrychunks.c3
-rw-r--r--libs/gst/base/gstbitwriter.c6
-rw-r--r--libs/gst/base/gstbytereader.c3
-rw-r--r--libs/gst/base/gstbytereader.h5
-rw-r--r--libs/gst/base/gstbytewriter.c4
-rw-r--r--libs/gst/base/gstindex.c3
-rw-r--r--tests/check/libs/bitwriter.c3
-rw-r--r--tests/check/libs/bytereader.c3
-rw-r--r--tests/check/libs/bytewriter.c5
10 files changed, 27 insertions, 11 deletions
diff --git a/gst/glib-compat-private.h b/gst/glib-compat-private.h
index 8f37de205e..617a50e4d1 100644
--- a/gst/glib-compat-private.h
+++ b/gst/glib-compat-private.h
@@ -30,6 +30,9 @@ G_BEGIN_DECLS
/* copies */
/* adaptations */
+#if !GLIB_CHECK_VERSION(2, 67, 4)
+#define g_memdup2(ptr,sz) ((G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL))
+#endif
G_END_DECLS
diff --git a/gst/gstregistrychunks.c b/gst/gstregistrychunks.c
index b352c45780..80d0d4ffc6 100644
--- a/gst/gstregistrychunks.c
+++ b/gst/gstregistrychunks.c
@@ -40,6 +40,7 @@
#include <gst/gstinfo.h>
#include <gst/gstenumtypes.h>
#include <gst/gstpadtemplate.h>
+#include "glib-compat-private.h"
#include <gst/gstregistrychunks.h>
@@ -95,7 +96,7 @@ _strnlen (const gchar * str, gint maxlen)
gint _len = _strnlen (inptr, (endptr-inptr)); \
if (_len == -1) \
goto error_label; \
- outptr = g_memdup ((gconstpointer)inptr, _len + 1); \
+ outptr = g_memdup2 ((gconstpointer)inptr, _len + 1); \
inptr += _len + 1; \
}G_STMT_END
diff --git a/libs/gst/base/gstbitwriter.c b/libs/gst/base/gstbitwriter.c
index 2f7f56ba4f..0947a680df 100644
--- a/libs/gst/base/gstbitwriter.c
+++ b/libs/gst/base/gstbitwriter.c
@@ -27,6 +27,8 @@
#define GST_BIT_WRITER_DISABLE_INLINES
#include "gstbitwriter.h"
+#include "gst/glib-compat-private.h"
+
/**
* SECTION:gstbitwriter
* @title: GstBitWriter
@@ -200,7 +202,7 @@ gst_bit_writer_reset_and_get_data (GstBitWriter * bitwriter)
data = bitwriter->data;
if (bitwriter->owned)
- data = g_memdup (data, bitwriter->bit_size >> 3);
+ data = g_memdup2 (data, bitwriter->bit_size >> 3);
gst_bit_writer_reset (bitwriter);
return data;
@@ -232,7 +234,7 @@ gst_bit_writer_reset_and_get_buffer (GstBitWriter * bitwriter)
/* we cannot rely on buffers allocated externally, thus let's dup
* the data */
if (data && !bitwriter->owned)
- data = g_memdup (data, size);
+ data = g_memdup2 (data, size);
buffer = gst_buffer_new ();
if (data != NULL) {
diff --git a/libs/gst/base/gstbytereader.c b/libs/gst/base/gstbytereader.c
index e9c2ec0ddd..c0a16efe3a 100644
--- a/libs/gst/base/gstbytereader.c
+++ b/libs/gst/base/gstbytereader.c
@@ -26,6 +26,7 @@
#define GST_BYTE_READER_DISABLE_INLINES
#include "gstbytereader.h"
+#include "gst/glib-compat-private.h"
#include <string.h>
/**
@@ -1222,7 +1223,7 @@ gst_byte_reader_dup_string_utf##bits (GstByteReader * reader, type ** str) \
*str = NULL; \
return FALSE; \
} \
- *str = g_memdup (reader->data + reader->byte, size); \
+ *str = g_memdup2 (reader->data + reader->byte, size); \
reader->byte += size; \
return TRUE; \
}
diff --git a/libs/gst/base/gstbytereader.h b/libs/gst/base/gstbytereader.h
index b988739a69..2130a8a008 100644
--- a/libs/gst/base/gstbytereader.h
+++ b/libs/gst/base/gstbytereader.h
@@ -362,7 +362,10 @@ static inline guint8 *
gst_byte_reader_dup_data_unchecked (GstByteReader * reader, guint size)
{
gconstpointer data = gst_byte_reader_get_data_unchecked (reader, size);
- return (guint8 *) g_memdup (data, size);
+ guint8 *dup_data = (guint8 *) g_malloc (size);
+
+ memcpy (dup_data, data, size);
+ return dup_data;
}
/* Unchecked variants that should not be used */
diff --git a/libs/gst/base/gstbytewriter.c b/libs/gst/base/gstbytewriter.c
index 335f22f5b8..aec10932e4 100644
--- a/libs/gst/base/gstbytewriter.c
+++ b/libs/gst/base/gstbytewriter.c
@@ -25,6 +25,8 @@
#define GST_BYTE_WRITER_DISABLE_INLINES
#include "gstbytewriter.h"
+#include "gst/glib-compat-private.h"
+
/**
* SECTION:gstbytewriter
* @title: GstByteWriter
@@ -236,7 +238,7 @@ gst_byte_writer_reset_and_get_data (GstByteWriter * writer)
data = (guint8 *) writer->parent.data;
if (!writer->owned)
- data = g_memdup (data, writer->parent.size);
+ data = g_memdup2 (data, writer->parent.size);
writer->parent.data = NULL;
gst_byte_writer_reset (writer);
diff --git a/libs/gst/base/gstindex.c b/libs/gst/base/gstindex.c
index d54e0feee9..964508e0ac 100644
--- a/libs/gst/base/gstindex.c
+++ b/libs/gst/base/gstindex.c
@@ -61,6 +61,7 @@
#endif
#include <gst/gst.h>
+#include "gst/glib-compat-private.h"
/* Index signals and args */
enum
@@ -798,7 +799,7 @@ gst_index_add_associationv (GstIndex * index, gint id,
entry->type = GST_INDEX_ENTRY_ASSOCIATION;
entry->id = id;
entry->data.assoc.flags = flags;
- entry->data.assoc.assocs = g_memdup (list, sizeof (GstIndexAssociation) * n);
+ entry->data.assoc.assocs = g_memdup2 (list, sizeof (GstIndexAssociation) * n);
entry->data.assoc.nassocs = n;
gst_index_add_entry (index, entry);
diff --git a/tests/check/libs/bitwriter.c b/tests/check/libs/bitwriter.c
index d6f68d32d9..4628a5b918 100644
--- a/tests/check/libs/bitwriter.c
+++ b/tests/check/libs/bitwriter.c
@@ -29,6 +29,7 @@
#include <gst/check/gstcheck.h>
#include <gst/base/gstbitwriter.h>
#include <gst/base/gstbitreader.h>
+#include "gst/glib-compat-private.h"
GST_START_TEST (test_initialization)
{
@@ -76,7 +77,7 @@ GST_START_TEST (test_data)
fail_unless (gst_bit_writer_put_bits_uint64 (&writer, 0x45, 48));
fail_unless_equals_int (gst_bit_writer_get_remaining (&writer), 2048 - 71);
fail_unless (gst_bit_writer_align_bytes (&writer, 0));
- data = g_memdup (sdata, sizeof (sdata));
+ data = g_memdup2 (sdata, sizeof (sdata));
fail_unless (gst_bit_writer_put_bytes (&writer, data, sizeof (sdata)));
gst_bit_reader_init (&reader, gst_bit_writer_get_data (&writer), 256);
diff --git a/tests/check/libs/bytereader.c b/tests/check/libs/bytereader.c
index 24a29714db..bc4c406327 100644
--- a/tests/check/libs/bytereader.c
+++ b/tests/check/libs/bytereader.c
@@ -27,6 +27,7 @@
#include <gst/gst.h>
#include <gst/check/gstcheck.h>
#include <gst/base/gstbytereader.h>
+#include "gst/glib-compat-private.h"
#ifndef fail_unless_equals_int64
#define fail_unless_equals_int64(a, b) \
@@ -574,7 +575,7 @@ GST_START_TEST (test_scan)
gint found;
/* dup so valgrind can detect out of bounds access more easily */
- m = g_memdup (sync_data, sizeof (sync_data));
+ m = g_memdup2 (sync_data, sizeof (sync_data));
gst_byte_reader_init (&reader, m, sizeof (sync_data));
found = gst_byte_reader_masked_scan_uint32_peek (&reader, 0xffffff00,
diff --git a/tests/check/libs/bytewriter.c b/tests/check/libs/bytewriter.c
index 89999af793..c8017b8347 100644
--- a/tests/check/libs/bytewriter.c
+++ b/tests/check/libs/bytewriter.c
@@ -27,6 +27,7 @@
#include <gst/gst.h>
#include <gst/check/gstcheck.h>
#include <gst/base/gstbytewriter.h>
+#include "gst/glib-compat-private.h"
GST_START_TEST (test_initialization)
{
@@ -42,7 +43,7 @@ GST_START_TEST (test_initialization)
(&writer)), 0);
gst_byte_writer_reset (&writer);
- data = g_memdup (sdata, sizeof (sdata));
+ data = g_memdup2 (sdata, sizeof (sdata));
gst_byte_writer_init_with_data (&writer, data, sizeof (sdata), FALSE);
fail_unless_equals_int (gst_byte_writer_get_pos (&writer), 0);
fail_unless_equals_int (gst_byte_writer_get_size (&writer), 0);
@@ -56,7 +57,7 @@ GST_START_TEST (test_initialization)
g_free (data);
data = tmp = NULL;
- data = g_memdup (sdata, sizeof (sdata));
+ data = g_memdup2 (sdata, sizeof (sdata));
gst_byte_writer_init_with_data (&writer, data, sizeof (sdata), TRUE);
fail_unless_equals_int (gst_byte_writer_get_pos (&writer), 0);
fail_unless_equals_int (gst_byte_writer_get_size (&writer), sizeof (sdata));