diff --git a/contrib/schemagen/test_gen.cpp b/contrib/schemagen/test_gen.cpp index 8dd23a3..4f2d5aa 100644 --- a/contrib/schemagen/test_gen.cpp +++ b/contrib/schemagen/test_gen.cpp @@ -68,6 +68,15 @@ int main() { expectReject(json, "unknown key in strict root"); } + // ---- invalid stack size is rejected without crashing ---- + { + RootBuilder b(-1); + char buf[] = "null"; + WeaselJsonStatus s = b.feed(buf, sizeof(buf) - 1); + CHECK(s == WeaselJson_REJECT); + printf("ok invalid stack size rejected, not crashed\n"); + } + { std::string json = R"({ "name": "Ada É", diff --git a/contrib/schemagen/weaseljson_schemagen.py b/contrib/schemagen/weaseljson_schemagen.py index 491d7e0..b70a51c 100644 --- a/contrib/schemagen/weaseljson_schemagen.py +++ b/contrib/schemagen/weaseljson_schemagen.py @@ -892,6 +892,10 @@ public: explicit RootBuilder(int stackSize = 1024) {{ cb_ = makeCallbacks(); parser_ = WeaselJsonParser_create(stackSize, &cb_, this, 0); + if (!parser_) {{ + error_ = true; + return; + }} {self._ctor_body()} }} ~RootBuilder() {{ if (parser_) WeaselJsonParser_destroy(parser_); }}