aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/CMakeLists.txt2
-rw-r--r--wsutil/glib-compat.c42
-rw-r--r--wsutil/glib-compat.h31
3 files changed, 75 insertions, 0 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt
index 207b1dce81..1d57e13ef0 100644
--- a/wsutil/CMakeLists.txt
+++ b/wsutil/CMakeLists.txt
@@ -66,6 +66,7 @@ set(WSUTIL_PUBLIC_HEADERS
unicode-utils.h
utf8_entities.h
ws_cpuid.h
+ glib-compat.h
ws_mempbrk.h
ws_mempbrk_int.h
ws_pipe.h
@@ -118,6 +119,7 @@ set(WSUTIL_COMMON_FILES
time_util.c
type_util.c
unicode-utils.c
+ glib-compat.c
ws_mempbrk.c
ws_pipe.c
wsgcrypt.c
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
diff --git a/wsutil/glib-compat.h b/wsutil/glib-compat.h
new file mode 100644
index 0000000000..788f5fb41c
--- /dev/null
+++ b/wsutil/glib-compat.h
@@ -0,0 +1,31 @@
+/* glib-compat.h
+* Definitions to 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
+*/
+#ifndef GLIB_COMPAT_H
+#define GLIB_COMPAT_H
+
+#include "ws_symbol_export.h"
+#include "ws_attributes.h"
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if !GLIB_CHECK_VERSION(2, 68, 0)
+WS_DLL_PUBLIC gpointer g_memdup2(gconstpointer mem, gsize byte_size);
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* GLIB_COMPAT_H */