From 597a8c736e2ed6f841b6b5d7f342453cc68d7355 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 12 Nov 2023 00:53:25 -0600 Subject: [PATCH] [ox/mc] Fix alloca use in loop --- deps/ox/src/ox/mc/read.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deps/ox/src/ox/mc/read.hpp b/deps/ox/src/ox/mc/read.hpp index bba31b01..d96e4d76 100644 --- a/deps/ox/src/ox/mc/read.hpp +++ b/deps/ox/src/ox/mc/read.hpp @@ -248,12 +248,17 @@ constexpr Error MetalClawReaderTemplate::field(const char*, HashMap(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)); } } }