tinyglib: implement g_strdup

Fixes AddressSanitizer with SLiRP enabled.
This commit is contained in:
David Hrdlička
2021-01-30 14:41:50 +01:00
parent c912c94e4f
commit 4fc03e7e13

View File

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