mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
util/register: fix crashing when value string contains non-ascii chars
We can't use RegGetValueA because RegGetValueA converts wide string to non UTF-8 string, which results in crashing when printing
This commit is contained in:
@@ -15,3 +15,22 @@ void ffWcharToUtf8(const wchar_t* input, FFstrbuf* result)
|
||||
result->length = (uint32_t)size_needed;
|
||||
result->chars[size_needed] = '\0';
|
||||
}
|
||||
|
||||
FFstrbuf ffStrbufFromWchar(const wchar_t* input)
|
||||
{
|
||||
FFstrbuf result;
|
||||
|
||||
int len = input ? (int)wcslen(input) : 0;
|
||||
if(len <= 0)
|
||||
ffStrbufInit(&result);
|
||||
else
|
||||
{
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, input, len, NULL, 0, NULL, NULL);
|
||||
ffStrbufInitA(&result, (uint32_t)size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, input, len, result.chars, size_needed, NULL, NULL);
|
||||
result.length = (uint32_t)size_needed;
|
||||
result.chars[size_needed] = '\0';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user