From 8fb15fcc922a302b88937a68e089223fb90640f9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 20 Apr 2023 14:14:43 +1200 Subject: Improve error for array size with a '<' character Previously we'd fail an assertion and dump core, which isn't nice: Bad template type passed to SwigType_remember: a(std::numeric_limits< unsigned char >::max()).unsigned char swig: ../../Source/Swig/typesys.c:1709: SwigType_remember_clientdata: Assertion `0' failed. Aborted (core dumped) We also now know that this situation can be triggered by particular user inputs, so an assertion is not an appropriate check anyway. Now we report an error and exit with non-zero status: :1: Error: Array size expressions containing a '<' character not fully supported The `:1:` part isn't ideal but happens because the SwigType doesn't seem to have file:line information. See #2486. --- Source/Swig/typesys.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index fc2224bf5..1d108dbde 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1700,10 +1700,13 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl if (t) { char *ct = Char(t); const char *lt = strchr(ct, '<'); - /* Allow for `<<` operator in constant expression for array size. */ - if (lt && lt[1] != '(' && lt[1] != '<') { - Printf(stdout, "Bad template type passed to SwigType_remember: %s\n", t); - assert(0); + if (lt && lt[1] != '(') { + /* We special case `<<` above, but most cases aren't handled, for example: + * + * unsigned char myarray[std::numeric_limits::max()]; // #2486 + */ + Swig_error(Getfile(t), Getline(t), "Array size expressions containing a '<' character not fully supported"); + Exit(EXIT_FAILURE); } } -- cgit v1.2.1