VST3: fix UTF-16 host message

This commit is contained in:
Robin Gareus
2020-10-26 18:33:10 +01:00
parent 8f67fc9c35
commit 722294075d
2 changed files with 8 additions and 4 deletions

View File

@@ -90,8 +90,9 @@ public:
: _size (size)
, _type (kString)
{
v.stringValue = new Vst::TChar[_size];
v.stringValue = new Vst::TChar[_size + 1];
memcpy (v.stringValue, value, _size * sizeof (Vst::TChar));
v.stringValue[size] = 0;
}
HostAttribute (const void* value, uint32 size)

View File

@@ -212,7 +212,7 @@ tresult
HostAttributeList::setString (AttrID aid, const Vst::TChar* string)
{
removeAttrID (aid);
list[aid] = new HostAttribute (string, wcslen ((const wchar_t*)string));
list[aid] = new HostAttribute (string, Steinberg::strlen16 (string));
return kResultTrue;
}
@@ -220,10 +220,13 @@ tresult
HostAttributeList::getString (AttrID aid, Vst::TChar* string, uint32 size)
{
std::map<std::string, HostAttribute*>::iterator it = list.find (aid);
if (it != list.end () && it->second) {
if (it != list.end () && it->second && size > 0) {
uint32 stringSize = 0;
const Vst::TChar* _string = it->second->stringValue (stringSize);
memcpy (string, _string, std::min<uint32> (stringSize, size) * sizeof (Vst::TChar));
size = std::min<uint32> (stringSize, size - 1);
memcpy (string, _string, size * sizeof (Vst::TChar));
string[size] = 0;
return kResultTrue;
}
return kResultFalse;