wsutil: Provide static inline g_memdup2 in glib-compat.h to not export it

Shared libraries should not export symbols exported by other libraries to avoid
collisions.

Fixes #17645.
This commit is contained in:
Balint Reczey 2021-10-11 19:11:09 +02:00
parent fdd1a82ed9
commit 9f92da75b8
4 changed files with 14 additions and 46 deletions

View File

@ -78,7 +78,6 @@ libwsutil.so.0 libwsutil0 #MINVER#
find_last_pathname_separator@Base 1.12.0~rc1
format_size_wmem@Base 3.5.0
free_progdirs@Base 2.3.0
g_memdup2@Base 3.5.0
get_basename@Base 1.12.0~rc1
get_copyright_info@Base 1.99.0
get_cur_groupname@Base 1.10.0

View File

@ -127,7 +127,6 @@ set(WSUTIL_COMMON_FILES
to_str.c
type_util.c
unicode-utils.c
glib-compat.c
ws_assert.c
ws_getopt.c
ws_mempbrk.c

View File

@ -1,43 +0,0 @@
/*
* Provide some functions that are not present in older
* GLIB versions (down to 2.22)
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <glib.h>
#include <string.h>
#include "glib-compat.h"
#if !GLIB_CHECK_VERSION(2, 68, 0)
/**
* g_memdup2:
* mem: the memory to copy
* byte_size: the number of bytes to copy.
*
* Allocates byte_size bytes of memory, and copies byte_size bytes into it from mem . If mem is NULL it returns NULL.
*
* This replaces g_memdup(), which was prone to integer overflows when converting the argument from a gsize to a guint.
*
* Since: 2.68
**/
gpointer
g_memdup2(gconstpointer mem, gsize byte_size)
{
gpointer new_mem;
if (mem && byte_size != 0) {
new_mem = g_malloc(byte_size);
memcpy(new_mem, mem, byte_size);
}
else
new_mem = NULL;
return new_mem;
}
#endif

View File

@ -21,7 +21,20 @@ extern "C" {
#endif /* __cplusplus */
#if !GLIB_CHECK_VERSION(2, 68, 0)
WS_DLL_PUBLIC gpointer g_memdup2(gconstpointer mem, gsize byte_size);
static inline gpointer
g_memdup2(gconstpointer mem, gsize byte_size)
{
gpointer new_mem;
if (mem && byte_size != 0) {
new_mem = g_malloc(byte_size);
memcpy(new_mem, mem, byte_size);
}
else
new_mem = NULL;
return new_mem;
}
#endif
#ifdef __cplusplus