From ac72db8ef04ad2f467627f0f37b834acdfb01c87 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 25 Jul 2015 16:01:43 -0700 Subject: [PATCH] Make our wgettext() implementation a little less terrifying Use wchar_t* directly instead of wcstring.c_str() --- src/wutil.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wutil.cpp b/src/wutil.cpp index 2faec2576..7b6c5c712 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -56,9 +56,9 @@ const file_id_t kInvalidFileID = {(dev_t)-1LL, (ino_t)-1LL, (uint64_t)-1LL, -1, /* Lock to protect wgettext */ static pthread_mutex_t wgettext_lock; -/* Maps string keys to (immortal) pointers to string values */ -typedef std::map wgettext_map_t; -static std::map wgettext_map; +/* Maps string keys to (immortal) pointers to string values. */ +typedef std::map wgettext_map_t; +static wgettext_map_t wgettext_map; void wutil_init() { @@ -481,15 +481,16 @@ const wchar_t *wgettext(const wchar_t *in) wcstring key = in; scoped_lock lock(wgettext_lock); - wcstring *& val = wgettext_map[key]; + // Reference to pointer to string + const wchar_t *& val = wgettext_map[key]; if (val == NULL) { cstring mbs_in = wcs2string(key); char *out = fish_gettext(mbs_in.c_str()); - val = new wcstring(format_string(L"%s", out)); //note that this writes into the map! + val = wcsdup(format_string(L"%s", out).c_str()); //note that this writes into the map! } errno = err; - return val->c_str(); //looks dangerous but is safe, since the string is stored in the map + return val; //looks dangerous but is safe, since the string is stored in the map } int wmkdir(const wcstring &name, int mode)