From 577dabf7b1ec020e8fb3e0b9106cabc40d0978b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 23 May 2021 23:51:27 +0100 Subject: [PATCH] Use g_memdup2() where available and add fallback for older GLib versions g_memdup() is deprecated since GLib 2.68 and we want to avoid deprecation warnings with recent versions of GLib. Part-of: --- ext/alsa/gstalsamidisrc.c | 2 +- ext/ogg/gstoggdemux.c | 6 +++--- gst-libs/gst/gl/x11/gstglcontext_glx.c | 2 +- gst-libs/gst/riff/riff-read.c | 8 ++++---- gst-libs/gst/rtp/gstrtcpbuffer.c | 4 ++-- gst-libs/gst/rtp/gstrtpbuffer.c | 2 +- gst-libs/gst/rtsp/gstrtspconnection.c | 2 +- gst-libs/gst/rtsp/gstrtspmessage.c | 2 +- gst-libs/gst/sdp/gstmikey.c | 2 +- gst-libs/gst/video/video-anc.c | 2 +- meson.build | 4 ++++ 11 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ext/alsa/gstalsamidisrc.c b/ext/alsa/gstalsamidisrc.c index 8816562..e388f42 100644 --- a/ext/alsa/gstalsamidisrc.c +++ b/ext/alsa/gstalsamidisrc.c @@ -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, diff --git a/ext/ogg/gstoggdemux.c b/ext/ogg/gstoggdemux.c index c8d61a8..0b1a104 100644 --- a/ext/ogg/gstoggdemux.c +++ b/ext/ogg/gstoggdemux.c @@ -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; diff --git a/gst-libs/gst/gl/x11/gstglcontext_glx.c b/gst-libs/gst/gl/x11/gstglcontext_glx.c index e581a7d..68d8e63 100644 --- a/gst-libs/gst/gl/x11/gstglcontext_glx.c +++ b/gst-libs/gst/gl/x11/gstglcontext_glx.c @@ -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; diff --git a/gst-libs/gst/riff/riff-read.c b/gst-libs/gst/riff/riff-read.c index 4972979..5e9f331 100644 --- a/gst-libs/gst/riff/riff-read.c +++ b/gst-libs/gst/riff/riff-read.c @@ -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); diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.c b/gst-libs/gst/rtp/gstrtcpbuffer.c index 29dfd82..876c4a9 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.c +++ b/gst-libs/gst/rtp/gstrtcpbuffer.c @@ -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; diff --git a/gst-libs/gst/rtp/gstrtpbuffer.c b/gst-libs/gst/rtp/gstrtpbuffer.c index 739b7d9..7d72cd9 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.c +++ b/gst-libs/gst/rtp/gstrtpbuffer.c @@ -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); } /** diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c index 27a2dac..92e144c 100644 --- a/gst-libs/gst/rtsp/gstrtspconnection.c +++ b/gst-libs/gst/rtsp/gstrtspconnection.c @@ -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); } diff --git a/gst-libs/gst/rtsp/gstrtspmessage.c b/gst-libs/gst/rtsp/gstrtspmessage.c index 3b693fa..dea5421 100644 --- a/gst-libs/gst/rtsp/gstrtspmessage.c +++ b/gst-libs/gst/rtsp/gstrtspmessage.c @@ -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); } /** diff --git a/gst-libs/gst/sdp/gstmikey.c b/gst-libs/gst/sdp/gstmikey.c index 4f8a313..cacabb7 100644 --- a/gst-libs/gst/sdp/gstmikey.c +++ b/gst-libs/gst/sdp/gstmikey.c @@ -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 { \ diff --git a/gst-libs/gst/video/video-anc.c b/gst-libs/gst/video/video-anc.c index bac275a..64d8792 100644 --- a/gst-libs/gst/video/video-anc.c +++ b/gst-libs/gst/video/video-anc.c @@ -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; diff --git a/meson.build b/meson.build index c2a6b1d..435679e 100644 --- a/meson.build +++ b/meson.build @@ -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) -- 2.7.4