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>
This commit is contained in:
Frediano Ziglio 2021-05-04 13:04:27 +01:00
parent 1fae1191e5
commit 8c458fa35e
10 changed files with 69 additions and 10 deletions

View File

@ -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 \

49
server/glib-compat.h Normal file
View File

@ -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_ */

View File

@ -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',

View File

@ -20,6 +20,7 @@
#include <glib.h>
#include <common/macros.h>
#include "glib-compat.h"
#include "red-channel-capabilities.h"
void red_channel_capabilities_init(RedChannelCapabilities *dest,
@ -27,11 +28,11 @@ void red_channel_capabilities_init(RedChannelCapabilities *dest,
{
*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));
}
}

View File

@ -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!

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}