diff options
author | Dario Lombardo <lomato@gmail.com> | 2021-03-23 16:41:54 +0100 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-03-25 09:38:10 +0000 |
commit | ea929d6401351916e0abca7429979eee9c47d3f2 (patch) | |
tree | 522492a802e608e8049fa5a3586477053002bce0 /wsutil/glib-compat.c | |
parent | e6df13076281a704e9dd1aa8c2afe3e7dce015e3 (diff) |
wsutils: add local implementation of g_memdup2.
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
Diffstat (limited to 'wsutil/glib-compat.c')
-rw-r--r-- | wsutil/glib-compat.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/wsutil/glib-compat.c b/wsutil/glib-compat.c new file mode 100644 index 0000000000..6a0afa28d5 --- /dev/null +++ b/wsutil/glib-compat.c @@ -0,0 +1,42 @@ +/* +* 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 "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 |