[ox/mc] Fix alloca use in loop

This commit is contained in:
Gary Talent 2023-11-12 00:53:25 -06:00
parent d9b676d1b2
commit 597a8c736e

View File

@ -248,12 +248,17 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, HashMap<Stri
auto reader = child("");
auto &handler = *reader.interface();
oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
for (std::size_t i = 0; i < len; ++i) {
// this loop body needs to be in a lambda because of the potential alloca call
constexpr auto loopBody = [](auto& handler) {
oxRequire(keyLen, handler.stringLength(nullptr));
auto wkey = ox_malloca(keyLen + 1, char, 0);
auto wkeyPtr = wkey.get();
oxReturnError(handler.fieldCString("", &wkeyPtr, keyLen + 1));
oxReturnError(handler.field("", &val->operator[](wkey.get())));
return OxError(0);
};
for (std::size_t i = 0; i < len; ++i) {
oxReturnError(loopBody(handler));
}
}
}