Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37543558
en ru br
Репозитории ALT

Группа :: Графические оболочки/Прочее
Пакет: SPICE

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: 0002-Fix-g_memdup-deprecation-warning-with-glib--268.patch
Скачать


From 8c458fa35e8979bb088cbc6d72f7bccd73f99189 Mon Sep 17 00:00:00 2001
From: Frediano Ziglio <freddy77@gmail.com>
Date: Tue, 4 May 2021 13:04:27 +0100
Subject: [PATCH] Fix g_memdup deprecation warning with glib >= 2.68
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-Andrц╘ Lureau <marcandre.lureau@redhat.com>
---
 server/Makefile.am                |  1 +
 server/glib-compat.h              | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 server/meson.build                |  1 +
 server/red-channel-capabilities.c |  5 +++--
 server/red-parse-qxl.cpp          |  4 +++-
 server/red-stream-device.cpp      |  3 ++-
 server/reds.cpp                   |  7 ++++---
 server/smartcard.cpp              |  3 ++-
 server/sound.cpp                  |  3 ++-
 server/websocket.c                |  3 ++-
 10 files changed, 69 insertions(+), 10 deletions(-)
 create mode 100644 server/glib-compat.h
diff --git a/server/Makefile.am b/server/Makefile.am
index 2b364ca..73e7cdf 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -107,6 +107,7 @@ libserver_la_SOURCES =				\
 	display-channel-private.h		\
 	display-limits.h			\
 	event-loop.c				\
+	glib-compat.h				\
 	glz-encoder.c				\
 	glz-encoder-dict.c			\
 	glz-encoder-dict.h			\
diff --git a/server/glib-compat.h b/server/glib-compat.h
new file mode 100644
index 0000000..5f36d3e
--- /dev/null
+++ b/server/glib-compat.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2021 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef GLIB_COMPAT_H_
+#define GLIB_COMPAT_H_
+
+#include <glib.h>
+
+#if GLIB_VERSION_MIN_REQUIRED >= G_ENCODE_VERSION(2, 68)
+#error Time to remove this section
+#elif !GLIB_CHECK_VERSION(2,68,0)
+static inline void*
+g_memdup2(const void *ptr, size_t size)
+{
+    void *dst = NULL;
+
+    if (ptr && size != 0) {
+        dst = g_malloc(size);
+        memcpy(dst, ptr, size);
+    }
+    return dst;
+}
+#elif GLIB_VERSION_MAX_ALLOWED < G_ENCODE_VERSION(2, 68)
+static inline void*
+g_memdup2_compat(const void *ptr, size_t size)
+{
+    G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+    return g_memdup2(ptr, size);
+    G_GNUC_END_IGNORE_DEPRECATIONS
+}
+#define g_memdup2 g_memdup2_compat
+#endif
+
+#endif /* GLIB_COMPAT_H_ */
diff --git a/server/meson.build b/server/meson.build
index 4a67063..f9cdf9d 100644
--- a/server/meson.build
+++ b/server/meson.build
@@ -78,6 +78,7 @@ spice_server_sources = [
   'display-channel-private.h',
   'display-limits.h',
   'event-loop.c',
+  'glib-compat.h',
   'glz-encoder.c',
   'glz-encoder-dict.c',
   'glz-encoder-dict.h',
diff --git a/server/red-channel-capabilities.c b/server/red-channel-capabilities.c
index 61685aa..f4b7fad 100644
--- a/server/red-channel-capabilities.c
+++ b/server/red-channel-capabilities.c
@@ -20,18 +20,19 @@
 #include <glib.h>
 #include <common/macros.h>
 
+#include "glib-compat.h"
 #include "red-channel-capabilities.h"
 
 void red_channel_capabilities_init(RedChannelCapabilities *dest,
                                    const RedChannelCapabilities *caps)
 {
     *dest = *caps;
     if (caps->common_caps) {
-        dest->common_caps = (uint32_t*) g_memdup(caps->common_caps,
+        dest->common_caps = (uint32_t*) g_memdup2(caps->common_caps,
                                      caps->num_common_caps * sizeof(uint32_t));
     }
     if (caps->num_caps) {
-        dest->caps = (uint32_t*) g_memdup(caps->caps, caps->num_caps * sizeof(uint32_t));
+        dest->caps = (uint32_t*) g_memdup2(caps->caps, caps->num_caps * sizeof(uint32_t));
     }
 }
 
diff --git a/server/red-parse-qxl.cpp b/server/red-parse-qxl.cpp
index 3575436..979d1b8 100644
--- a/server/red-parse-qxl.cpp
+++ b/server/red-parse-qxl.cpp
@@ -20,6 +20,8 @@
 #include <inttypes.h>
 #include <glib.h>
 #include <common/lz_common.h>
+
+#include "glib-compat.h"
 #include "spice-bitmap-utils.h"
 #include "red-common.h"
 #include "red-qxl.h"
@@ -1562,7 +1564,7 @@ static bool red_get_cursor(RedMemSlotInfo *slots, int group_id,
     if (free_data) {
         red->data = data;
     } else {
-        red->data = (uint8_t*) g_memdup(data, size);
+        red->data = (uint8_t*) g_memdup2(data, size);
     }
     // Arrived here we could note that we are not going to use anymore cursor data
     // and we could be tempted to release resource back to QXL. Don't do that!
diff --git a/server/red-stream-device.cpp b/server/red-stream-device.cpp
index 224187d..fe53a3c 100644
--- a/server/red-stream-device.cpp
+++ b/server/red-stream-device.cpp
@@ -19,6 +19,7 @@
 
 #include <common/recorder.h>
 
+#include "glib-compat.h"
 #include "red-stream-device.h"
 
 #include "stream-channel.h"
@@ -416,7 +417,7 @@ stream_msg_cursor_set_to_cursor_cmd(const StreamMsgCursorSet *msg, size_t msg_si
         return nullptr;
     }
     cursor->data_size = size_required;
-    cursor->data = (uint8_t*) g_memdup(msg->data, size_required);
+    cursor->data = (uint8_t*) g_memdup2(msg->data, size_required);
     return cmd;
 }
 
diff --git a/server/reds.cpp b/server/reds.cpp
index fa6e393..b31a6a5 100644
--- a/server/reds.cpp
+++ b/server/reds.cpp
@@ -53,6 +53,7 @@
 #include <common/generated_server_marshallers.h>
 #include <common/agent.h>
 
+#include "glib-compat.h"
 #include "spice-wrapped.h"
 #include "reds.h"
 #include "agent-msg-filter.h"
@@ -1458,7 +1459,7 @@ bool reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc,
             /* restore agent state when the agent gets attached */
             spice_debug("saving mig_data");
             spice_assert(agent_dev->priv->plug_generation == 0);
-            agent_dev->priv->mig_data = (SpiceMigrateDataMain*) g_memdup(mig_data, size);
+            agent_dev->priv->mig_data = (SpiceMigrateDataMain*) g_memdup2(mig_data, size);
         }
     } else {
         spice_debug("agent was not attached on the source host");
@@ -1746,13 +1747,13 @@ red_channel_capabilities_init_from_link_message(RedChannelCapabilities *caps,
     caps->num_common_caps = link_mess->num_common_caps;
     caps->common_caps = nullptr;
     if (caps->num_common_caps) {
-        caps->common_caps = (uint32_t*) g_memdup(raw_caps,
+        caps->common_caps = (uint32_t*) g_memdup2(raw_caps,
                                      link_mess->num_common_caps * sizeof(uint32_t));
     }
     caps->num_caps = link_mess->num_channel_caps;
     caps->caps = nullptr;
     if (link_mess->num_channel_caps) {
-        caps->caps = (uint32_t*) g_memdup(raw_caps + link_mess->num_common_caps * sizeof(uint32_t),
+        caps->caps = (uint32_t*) g_memdup2(raw_caps + link_mess->num_common_caps * sizeof(uint32_t),
                               link_mess->num_channel_caps * sizeof(uint32_t));
     }
 }
diff --git a/server/smartcard.cpp b/server/smartcard.cpp
index e76ec03..709815a 100644
--- a/server/smartcard.cpp
+++ b/server/smartcard.cpp
@@ -22,6 +22,7 @@
 #include <libcacard.h>
 #endif
 
+#include "glib-compat.h"
 #include "reds.h"
 #include "char-device.h"
 #include "smartcard.h"
@@ -389,7 +390,7 @@ smartcard_new_vsc_msg_item(unsigned int reader_id, const VSCMsgHeader *vheader)
 {
     auto msg_item = red::make_shared<RedMsgItem>();
 
-    msg_item->vheader.reset((VSCMsgHeader*) g_memdup(vheader, sizeof(*vheader) + vheader->length));
+    msg_item->vheader.reset((VSCMsgHeader*) g_memdup2(vheader, sizeof(*vheader) + vheader->length));
     /* We patch the reader_id, since the device only knows about itself, and
      * we know about the sum of readers. */
     msg_item->vheader->reader_id = reader_id;
diff --git a/server/sound.cpp b/server/sound.cpp
index 66743af..0c93019 100644
--- a/server/sound.cpp
+++ b/server/sound.cpp
@@ -31,6 +31,7 @@
 #include <common/generated_server_marshallers.h>
 #include <common/snd_codec.h>
 
+#include "glib-compat.h"
 #include "spice-wrapped.h"
 #include "red-common.h"
 #include "main-channel.h"
@@ -790,7 +791,7 @@ static void snd_channel_set_volume(SndChannel *channel,
 
     st->volume_nchannels = nchannels;
     g_free(st->volume);
-    st->volume = (uint16_t*) g_memdup(volume, sizeof(uint16_t) * nchannels);
+    st->volume = (uint16_t*) g_memdup2(volume, sizeof(uint16_t) * nchannels);
 
     if (!client || nchannels == 0)
         return;
diff --git a/server/websocket.c b/server/websocket.c
index 6b974cc..f9b9ea3 100644
--- a/server/websocket.c
+++ b/server/websocket.c
@@ -36,6 +36,7 @@
 #include <common/mem.h>
 
 #include "sys-socket.h"
+#include "glib-compat.h"
 #include "websocket.h"
 
 #ifdef _WIN32
@@ -487,7 +488,7 @@ static void constrain_iov(struct iovec *iov, int iovcnt,
         if (iov[i].iov_len > maxlen) {
             /* TODO - This code has never triggered afaik... */
             *iov_out_cnt = ++i;
-            *iov_out = g_memdup(iov, i * sizeof (*iov));
+            *iov_out = g_memdup2(iov, i * sizeof (*iov));
             (*iov_out)[i-1].iov_len = maxlen;
             return;
         }
--
libgit2 1.3.0
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin