Unknown opcodes were truncated by the C wrapper

Thanks @alcomposer for the patch
Fixes #18
This commit is contained in:
Paul Ferrand 2019-12-29 18:11:22 +01:00
parent 2c8a286e37
commit 693a2008a9

View file

@ -222,20 +222,19 @@ char* sfizz_get_unknown_opcodes(sfizz_synth_t* synth)
const auto unknownOpcodes = self->getUnknownOpcodes(); const auto unknownOpcodes = self->getUnknownOpcodes();
int totalLength = 0; int totalLength = 0;
for (auto& opcode: unknownOpcodes) for (auto& opcode: unknownOpcodes)
totalLength += opcode.length(); totalLength += opcode.length() + 1;
if (totalLength == 0) if (totalLength == 0)
return nullptr; return nullptr;
auto opcodeList = (char *)std::malloc(totalLength + unknownOpcodes.size()); auto opcodeList = (char *)std::malloc(totalLength);
auto listIterator = opcodeList; auto listIterator = opcodeList;
for (auto& opcode: unknownOpcodes) { for (auto& opcode : unknownOpcodes) {
std::copy(opcode.begin(), opcode.end(), listIterator); std::copy(opcode.begin(), opcode.end(), listIterator);
listIterator += opcode.length(); listIterator += opcode.length();
*listIterator++ = ','; *listIterator++ = (opcode == *unknownOpcodes.rbegin()) ? '\0' : ',';
} }
opcodeList[totalLength] = '\0';
return opcodeList; return opcodeList;
} }