Use g_memdup2() where available and add fallback for older GLib versions
authorTim-Philipp Müller <tim@centricular.com>
Sun, 23 May 2021 22:51:27 +0000 (23:51 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 2 Jun 2021 14:21:02 +0000 (14:21 +0000)
g_memdup() is deprecated since GLib 2.68 and we want to avoid
deprecation warnings with recent versions of GLib.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1171>

ext/alsa/gstalsamidisrc.c
ext/ogg/gstoggdemux.c
gst-libs/gst/gl/x11/gstglcontext_glx.c
gst-libs/gst/riff/riff-read.c
gst-libs/gst/rtp/gstrtcpbuffer.c
gst-libs/gst/rtp/gstrtpbuffer.c
gst-libs/gst/rtsp/gstrtspconnection.c
gst-libs/gst/rtsp/gstrtspmessage.c
gst-libs/gst/sdp/gstmikey.c
gst-libs/gst/video/video-anc.c
meson.build

index 8816562..e388f42 100644 (file)
@@ -420,7 +420,7 @@ push_buffer (GstAlsaMidiSrc * alsamidisrc, gpointer data, guint size,
   GST_BUFFER_DTS (buffer) = time;
   GST_BUFFER_PTS (buffer) = time;
 
-  local_data = g_memdup (data, size);
+  local_data = g_memdup2 (data, size);
 
   gst_buffer_append_memory (buffer,
       gst_memory_new_wrapped (0, local_data, size, 0, size, local_data,
index c8d61a8..0b1a104 100644 (file)
@@ -87,7 +87,7 @@ _ogg_packet_copy (const ogg_packet * packet)
   ogg_packet *ret = g_slice_new (ogg_packet);
 
   *ret = *packet;
-  ret->packet = g_memdup (packet->packet, packet->bytes);
+  ret->packet = g_memdup2 (packet->packet, packet->bytes);
 
   return ret;
 }
@@ -105,9 +105,9 @@ gst_ogg_page_copy (ogg_page * page)
   ogg_page *p = g_slice_new (ogg_page);
 
   /* make a copy of the page */
-  p->header = g_memdup (page->header, page->header_len);
+  p->header = g_memdup2 (page->header, page->header_len);
   p->header_len = page->header_len;
-  p->body = g_memdup (page->body, page->body_len);
+  p->body = g_memdup2 (page->body, page->body_len);
   p->body_len = page->body_len;
 
   return p;
index e581a7d..68d8e63 100644 (file)
@@ -512,7 +512,7 @@ fb_config_attributes_from_structure (GstStructure * config)
       None
     };
 
-    return g_memdup (attribs, sizeof (attribs));
+    return g_memdup2 (attribs, sizeof (attribs));
   }
 
   n = gst_structure_n_fields (config) * 2 + 1;
index 4972979..5e9f331 100644 (file)
@@ -293,7 +293,7 @@ gst_riff_parse_strh (GstElement * element,
   if (info.size < sizeof (gst_riff_strh))
     goto too_small;
 
-  strh = g_memdup (info.data, info.size);
+  strh = g_memdup2 (info.data, info.size);
   gst_buffer_unmap (buf, &info);
 
   gst_buffer_unref (buf);
@@ -384,7 +384,7 @@ gst_riff_parse_strf_vids (GstElement * element,
   if (info.size < sizeof (gst_riff_strf_vids))
     goto too_small;
 
-  strf = g_memdup (info.data, info.size);
+  strf = g_memdup2 (info.data, info.size);
   gst_buffer_unmap (buf, &info);
 
 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
@@ -482,7 +482,7 @@ gst_riff_parse_strf_auds (GstElement * element,
   if (info.size < sizeof (gst_riff_strf_auds))
     goto too_small;
 
-  strf = g_memdup (info.data, info.size);
+  strf = g_memdup2 (info.data, info.size);
 
 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
   strf->format = GUINT16_FROM_LE (strf->format);
@@ -574,7 +574,7 @@ gst_riff_parse_strf_iavs (GstElement * element,
   if (info.size < sizeof (gst_riff_strf_iavs))
     goto too_small;
 
-  strf = g_memdup (info.data, info.size);
+  strf = g_memdup2 (info.data, info.size);
   gst_buffer_unmap (buf, &info);
 
   gst_buffer_unref (buf);
index 29dfd82..876c4a9 100644 (file)
@@ -84,7 +84,7 @@ gst_rtcp_buffer_new_take_data (gpointer data, guint len)
 GstBuffer *
 gst_rtcp_buffer_new_copy_data (gconstpointer data, guint len)
 {
-  return gst_rtcp_buffer_new_take_data (g_memdup (data, len), len);
+  return gst_rtcp_buffer_new_take_data (g_memdup2 (data, len), len);
 }
 
 static gboolean
@@ -1213,7 +1213,7 @@ gst_rtcp_packet_copy_profile_specific_ext (GstRTCPPacket * packet,
     if (data != NULL) {
       guint8 *ptr = packet->rtcp->map.data + packet->offset;
       ptr += ((packet->length + 1 - pse_len) * sizeof (guint32));
-      *data = g_memdup (ptr, pse_len * sizeof (guint32));
+      *data = g_memdup2 (ptr, pse_len * sizeof (guint32));
     }
 
     return TRUE;
index 739b7d9..7d72cd9 100644 (file)
@@ -184,7 +184,7 @@ gst_rtp_buffer_new_take_data (gpointer data, gsize len)
 GstBuffer *
 gst_rtp_buffer_new_copy_data (gconstpointer data, gsize len)
 {
-  return gst_rtp_buffer_new_take_data (g_memdup (data, len), len);
+  return gst_rtp_buffer_new_take_data (g_memdup2 (data, len), len);
 }
 
 /**
index 27a2dac..92e144c 100644 (file)
@@ -4519,7 +4519,7 @@ gst_rtsp_watch_write_serialized_messages (GstRTSPWatch * watch,
      * we don't own them here */
     if (local_message.body_data) {
       local_message.body_data =
-          g_memdup (local_message.body_data, local_message.body_data_size);
+          g_memdup2 (local_message.body_data, local_message.body_data_size);
     } else if (local_message.body_buffer) {
       gst_buffer_ref (local_message.body_buffer);
     }
index 3b693fa..dea5421 100644 (file)
@@ -943,7 +943,7 @@ gst_rtsp_message_set_body (GstRTSPMessage * msg, const guint8 * data,
 {
   g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL);
 
-  return gst_rtsp_message_take_body (msg, g_memdup (data, size), size);
+  return gst_rtsp_message_take_body (msg, g_memdup2 (data, size), size);
 }
 
 /**
index 4f8a313..cacabb7 100644 (file)
@@ -66,7 +66,7 @@ G_STMT_START {                    \
 #define INIT_MEMDUP(field, data, len)            \
 G_STMT_START {                                   \
   g_free ((field));                              \
-  (field) = g_memdup (data, len);                \
+  (field) = g_memdup2 (data, len);                \
 } G_STMT_END
 #define FREE_MEMDUP(field)                       \
 G_STMT_START {                                   \
index bac275a..64d8792 100644 (file)
@@ -1031,7 +1031,7 @@ gst_buffer_add_video_caption_meta (GstBuffer * buffer,
   g_return_val_if_fail (meta != NULL, NULL);
 
   meta->caption_type = caption_type;
-  meta->data = g_memdup (data, size);
+  meta->data = g_memdup2 (data, size);
   meta->size = size;
 
   return meta;
index c2a6b1d..435679e 100644 (file)
@@ -527,6 +527,10 @@ if gst_version_nano == 0
   endif
 endif
 
+if gio_dep.version().version_compare('< 2.67.4')
+  core_conf.set('g_memdup2(ptr,sz)', '(G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL)')
+endif
+
 # Use core_conf after all subdirs have set values
 configure_file(output : 'config.h', configuration : core_conf)