leftibot f1a0c2ae41 Fix #635: Segfault in optimized for-loop when := copies stack-local variable
The optimized for-loop in chaiscript_optimizer.hpp stored the loop counter
as a stack-local int and exposed it to ChaiScript via var(&i), creating a
reference. When the := operator was used inside the loop body (e.g.
ret := i), it copied the raw pointers to this stack variable into the
target's Data. When the function returned via exception unwinding, the
stack frame was destroyed, leaving dangling pointers in the return value.
Accessing these pointers in the caller (e.g. via string interpolation)
caused a segfault. The fix heap-allocates the loop counter via
std::make_shared<int>, so the data survives scope exit through
reference counting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 09:35:51 -06:00
..
dispatchkit Fix #17: Add const variables in ChaiScript (#643) 2026-04-10 22:12:13 -06:00
language Fix #635: Segfault in optimized for-loop when := copies stack-local variable 2026-04-11 09:35:51 -06:00
utility Fix #477: Handle \u unicode escape sequences in JSON parser 2026-04-10 19:49:48 -06:00
chaiscript_basic.hpp change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
chaiscript_defines.hpp change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
chaiscript_stdlib.hpp change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
chaiscript_threading.hpp change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
chaiscript.hpp change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00