From 4fc03e7e131e50acd4ddc949f05d5fb4342ad405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 30 Jan 2021 14:41:50 +0100 Subject: [PATCH] tinyglib: implement `g_strdup` Fixes AddressSanitizer with SLiRP enabled. --- src/include/tinyglib.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h index fabdefcfc..686257e7f 100644 --- a/src/include/tinyglib.h +++ b/src/include/tinyglib.h @@ -215,6 +215,24 @@ g_strv_length(gchar **str_array) } +/* Implementation borrowed from GLib itself. */ +static gchar* +g_strdup(const gchar *str) +{ + gchar *new_str; + gsize length; + + if (str) { + length = strlen(str) + 1; + new_str = malloc(sizeof(char) * length); + memcpy(new_str, str, length); + } else + new_str = NULL; + + return new_str; +} + + /* Macros */ #define tinyglib_pclog(f, s, ...) pclog("TinyGLib " f "(): " s "\n", ##__VA_ARGS__) @@ -271,7 +289,6 @@ g_strv_length(gchar **str_array) #define g_rand_free free #define g_realloc realloc #define g_snprintf snprintf -#define g_strdup strdup #define g_strerror strerror #define g_strfreev free #define g_string_append_printf sprintf /* unimplemented */