[ox/mc] Fix string allocation size

This commit is contained in:
Gary Talent 2020-06-20 02:55:25 -05:00
parent b6f8c9e242
commit 5c34c26080
2 changed files with 2 additions and 2 deletions

View File

@ -143,7 +143,7 @@ std::map<std::string, ox::Error(*)()> tests = {
testIn.Struct.String = "Test String 2"; testIn.Struct.String = "Test String 2";
oxAssert(ox::writeMC(buff, buffLen, &testIn), "writeMC failed"); oxAssert(ox::writeMC(buff, buffLen, &testIn), "writeMC failed");
oxAssert(ox::readMC(buff, buffLen, &testOut), "writeMC failed"); oxAssert(ox::readMC(buff, buffLen, &testOut), "readMC failed");
//std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n"; //std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n";
oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch"); oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch");

View File

@ -185,7 +185,7 @@ template<typename T>
for (std::size_t i = 0; i < len; i++) { for (std::size_t i = 0; i < len; i++) {
auto &key = keys[i]; auto &key = keys[i];
const auto keyLen = ox_strlen(key); const auto keyLen = ox_strlen(key);
auto wkey = static_cast<char*>(ox_alloca(keyLen)); auto wkey = static_cast<char*>(ox_alloca(keyLen + 1));
memcpy(wkey, key.c_str(), keyLen + 1); memcpy(wkey, key.c_str(), keyLen + 1);
oxReturnError(writer.field("", SerStr(&wkey, keyLen))); oxReturnError(writer.field("", SerStr(&wkey, keyLen)));
oxReturnError(writer.field("", &(*val)[key])); oxReturnError(writer.field("", &(*val)[key]));