p-ranav / indicators

Activity Indicators for Modern C++
MIT License
3.04k stars 237 forks source link

setlocale in utf8_decode will throw std::logic_error when setlocale returns NULL #128

Open sean2077 opened 11 months ago

sean2077 commented 11 months ago

In unicode::details::utf8_decode function:

static inline std::wstring utf8_decode(const std::string& s) {
            std::string curLocale = setlocale(LC_ALL, "");
            const char* _Source = s.c_str();
            size_t _Dsize = mbstowcs(NULL, _Source, 0) + 1;
            wchar_t* _Dest = new wchar_t[_Dsize];
            wmemset(_Dest, 0, _Dsize);
            mbstowcs(_Dest, _Source, _Dsize);
            std::wstring result = _Dest;
            delete[] _Dest;
            setlocale(LC_ALL, curLocale.c_str());
            return result;
        }

std::string curLocale = setlocale(LC_ALL, ""); will throw std::logic_error when setlocale(LC_ALL, "") return NULL