2 Commits

Author SHA1 Message Date
leftibot
ec05fcf3d4 Address review: tighten max_call_depth on MSVC Debug
Windows MSVC Debug builds crashed unit.recursion_depth_protection.chai
with SEGFAULT before the depth check could fire. Windows defaults to a
1 MiB thread stack and Debug builds emit much larger per-frame native
stack usage (no inlining, /RTC, buffer security checks), so 256 nested
ChaiScript calls overflow the native stack long before the dispatcher
reaches max_call_depth. Linux/macOS and MSVC Release pass at 256.

Pick a tighter default (32) only for the MSVC + _DEBUG configuration
that needs it, leaving every other build at the original 256, and shrink
the count_down recursion in the regression test so the bounded path
stays well below every platform's default.

Requested by @lefticus in PR #700 review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 16:54:56 -06:00
leftibot
5cf5049549 Fix #633: Bound ChaiScript call stack to prevent native stack overflow
Recursive user-defined operators (e.g. a `string::/=` whose body calls
itself through string interpolation) drove the AST evaluator into
unbounded native recursion and crashed the host process with SIGSEGV.
The dispatcher now refuses to enter a new function frame once
`Stack_Holder::call_depth` reaches `chaiscript::max_call_depth`
(default 256, overridable via the `CHAISCRIPT_MAX_CALL_DEPTH` macro)
and throws the new `chaiscript::exception::stack_overflow_error`
instead, letting both ChaiScript-level `try`/`catch` and C++ hosts
recover from runaway recursion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 16:03:20 -06:00