summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ejdestig <marejde@gmail.com>2019-04-18 07:03:03 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2019-04-18 14:44:21 +0200
commit8d358cea68b00e079057c3f785fb405c8286708f (patch)
tree2496c3d87efca7f4756b72ed99c947d5dabf4189
parent021bfe1ea539e136c170526563697970ebc318b8 (diff)
downloadglibmm-8d358cea68b00e079057c3f785fb405c8286708f.tar.gz
Use convert_return_gchar_ptr_to_*() in a couple of ustring methods
First attempt at fixing memory leak in make_valid() (see previous commit) used make_unique_ptr_gfree() directly because of looking at these methods. Better to use the helper function. This actually fixes undefined behavior for normalize() since g_utf8_normalize() is documented to return NULL if string is not a valid UTF-8 string. The constructor for std::string, which ustring uses for storage, that takes a pointer is documented to have undefined behavior if pointer is NULL. The utility function checks for NULL and uses the default constructor in that case. (Have not looked at implementation of Glib functions, and it may be that all std::string implementations Glibmm is used with handles this case, but good to avoid undefined behavior regardless, I think.)
-rw-r--r--glib/glibmm/ustring.cc15
1 files changed, 5 insertions, 10 deletions
diff --git a/glib/glibmm/ustring.cc b/glib/glibmm/ustring.cc
index abd1b580..a0f9ab80 100644
--- a/glib/glibmm/ustring.cc
+++ b/glib/glibmm/ustring.cc
@@ -1236,37 +1236,32 @@ ustring::is_ascii() const
ustring
ustring::normalize(NormalizeMode mode) const
{
- const auto buf = make_unique_ptr_gfree(
+ return convert_return_gchar_ptr_to_ustring(
g_utf8_normalize(string_.data(), string_.size(), static_cast<GNormalizeMode>(int(mode))));
- return ustring(buf.get());
}
ustring
ustring::uppercase() const
{
- const auto buf = make_unique_ptr_gfree(g_utf8_strup(string_.data(), string_.size()));
- return ustring(buf.get());
+ return convert_return_gchar_ptr_to_ustring(g_utf8_strup(string_.data(), string_.size()));
}
ustring
ustring::lowercase() const
{
- const auto buf = make_unique_ptr_gfree(g_utf8_strdown(string_.data(), string_.size()));
- return ustring(buf.get());
+ return convert_return_gchar_ptr_to_ustring(g_utf8_strdown(string_.data(), string_.size()));
}
ustring
ustring::casefold() const
{
- const auto buf = make_unique_ptr_gfree(g_utf8_casefold(string_.data(), string_.size()));
- return ustring(buf.get());
+ return convert_return_gchar_ptr_to_ustring(g_utf8_casefold(string_.data(), string_.size()));
}
std::string
ustring::collate_key() const
{
- const auto buf = make_unique_ptr_gfree(g_utf8_collate_key(string_.data(), string_.size()));
- return std::string(buf.get());
+ return convert_return_gchar_ptr_to_stdstring(g_utf8_collate_key(string_.data(), string_.size()));
}
std::string