From 27ca0db7a6143d2e479ff1ae52ec7c349ab1d4f2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 7 Jan 2014 23:33:46 +0100 Subject: util/Alloc: new library replacing GLib's g_malloc() --- src/tag/TagString.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/tag/TagString.cxx') diff --git a/src/tag/TagString.cxx b/src/tag/TagString.cxx index 3e8d8c1b0..9d2bd68ec 100644 --- a/src/tag/TagString.cxx +++ b/src/tag/TagString.cxx @@ -19,11 +19,13 @@ #include "config.h" #include "TagString.hxx" +#include "util/Alloc.hxx" #include #include #include +#include /** * Replace invalid sequences with the question mark. @@ -33,7 +35,7 @@ patch_utf8(const char *src, size_t length, const gchar *end) { /* duplicate the string, and replace invalid bytes in that buffer */ - char *dest = g_strdup(src); + char *dest = xstrdup(src); do { dest[end - src] = '?'; @@ -58,9 +60,12 @@ fix_utf8(const char *str, size_t length) /* no, it's not - try to import it from ISO-Latin-1 */ temp = g_convert(str, length, "utf-8", "iso-8859-1", nullptr, &written, nullptr); - if (temp != nullptr) + if (temp != nullptr) { /* success! */ - return temp; + char *p = xstrdup(temp); + g_free(temp); + return p; + } /* no, still broken - there's no medication, just patch invalid sequences */ @@ -96,7 +101,7 @@ clear_non_printable(const char *p, size_t length) if (first == nullptr) return nullptr; - dest = g_strndup(p, length); + dest = xstrndup(p, length); for (size_t i = first - p; i < length; ++i) if (char_is_non_printable(dest[i])) @@ -120,7 +125,7 @@ FixTagString(const char *p, size_t length) if (cleared == nullptr) cleared = utf8; else - g_free(utf8); + free(utf8); return cleared; } -- cgit v1.2.3