summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-04-20 14:14:43 +1200
committerOlly Betts <olly@survex.com>2023-04-20 14:14:43 +1200
commit8fb15fcc922a302b88937a68e089223fb90640f9 (patch)
tree2588ea70b669ac1a955f27d5d1a250107afa325c
parent9873ff107af2f9dea05ddb9a48b9c2d7abbfd5dc (diff)
downloadswig-8fb15fcc922a302b88937a68e089223fb90640f9.tar.gz
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.
-rw-r--r--Source/Swig/typesys.c11
1 files 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<unsigned char>::max()]; // #2486
+ */
+ Swig_error(Getfile(t), Getline(t), "Array size expressions containing a '<' character not fully supported");
+ Exit(EXIT_FAILURE);
}
}