ini: fixed insufficient utf8->16 alloc

This commit is contained in:
Hane 2024-12-12 20:29:13 +01:00
commit 9f7e7e30e2
2 changed files with 14 additions and 9 deletions

View file

@ -941,11 +941,15 @@ HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent) {
}
connect(channels, &QCheckBox::stateChanged, [this, parent](){
set->setValue("show_channels", channels->isChecked(), sizeof("show_channels"));
if(!OverseerHandler::settingsPath.empty())
if(!OverseerHandler::settingsPath.empty()){
set->save(OverseerHandler::settingsPath.c_str());
if(parent)
QCoreApplication::instance()->postEvent
(parent, new QEvent((QEvent::Type)CustomQEvent::RecomposeMainWindow));
}
if(parent) {
QEvent explosion = QEvent((QEvent::Type)CustomQEvent::RecomposeMainWindow);
QCoreApplication::instance()->sendEvent
(parent, &explosion);
}
});

View file

@ -3,11 +3,11 @@
namespace ini {
wchar_t* utf8toUtf16(const char* str, uint64_t* size = nullptr) {
wchar_t* Utf8toUtf16(const char* str, uint64_t* size = nullptr) {
if(!str || str[0] == '\0') return nullptr;
int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if(size) *size = sizeNeeded;
wchar_t* utf16 = (wchar_t*)calloc(sizeNeeded, 1);
wchar_t* utf16 = (wchar_t*)calloc(sizeNeeded, sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, str, -1, utf16, sizeNeeded);
return utf16;
}
@ -100,7 +100,7 @@ namespace ini {
if(!path) return false;
uint64_t convertedPathSize = 0;
wchar_t* convertedPath = utf8toUtf16(path, &convertedPathSize);
wchar_t* convertedPath = Utf8toUtf16(path, &convertedPathSize);
if(!convertedPath) return false;
wchar_t* utf16Path = (wchar_t*)calloc(maxPathBypassLen + convertedPathSize, sizeof(wchar_t));
memcpy(utf16Path, maxPathBypass, sizeof(wchar_t) * maxPathBypassLen);
@ -166,6 +166,7 @@ namespace ini {
else return false;
return false;
#undef releaseBeforeReturn
}
UserSettings::~UserSettings() {
@ -179,7 +180,7 @@ namespace ini {
UserSettings* UserSettings::createSettings(const char* path, bool create) {
if(!path) return nullptr;
wchar_t* utf16Path = utf8toUtf16(path);
wchar_t* utf16Path = Utf8toUtf16(path);
if(!utf16Path) return nullptr;
#define releaseBeforeReturn() do { \