Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sean2077 opened this issue Nov 21, 2023 · 0 comments

Comments

@sean2077
Copy link
Contributor

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

@sean2077 sean2077 changed the title setlocale in utf8_decode will throw std::logic_error when setlocale(LC_ALL, "") return NULL setlocale in utf8_decode will throw std::logic_error when setlocale returns NULL Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant