From ca5c68e5441fa8334381bd26ea2ff5132c26e6ab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 22 Nov 2022 21:40:38 +0000 Subject: [PATCH] Fix seg fault handling template parameter expressions containing '>=' Similar to previous commit Issue #1037 --- CHANGES.current | 3 ++- Examples/test-suite/cpp17_enable_if_t.i | 3 --- Source/Swig/typeobj.c | 22 ++++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index e3165b178..2e991b61b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,7 +8,8 @@ Version 4.2.0 (in progress) =========================== 2022-11-22: wsfulton - #1037 Fix seg fault handling template parameter expressions containing '<='. + #1037 Fix seg fault handling template parameter expressions containing '<=' + or '>='. 2022-11-18: wsfulton Duplicate class template instantiations via %template now issue a warning and are ignored. diff --git a/Examples/test-suite/cpp17_enable_if_t.i b/Examples/test-suite/cpp17_enable_if_t.i index 7c188dcfa..46515b9a3 100644 --- a/Examples/test-suite/cpp17_enable_if_t.i +++ b/Examples/test-suite/cpp17_enable_if_t.i @@ -44,9 +44,6 @@ void tester() { template > void destId(T el) {} -/* -not yet fixed template = 3>> void destId(const T& el) {} -*/ %} diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 569d2a406..584e2424b 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -1043,16 +1043,17 @@ String *SwigType_templateprefix(const SwigType *t) { * ----------------------------------------------------------------------------- */ String *SwigType_templatesuffix(const SwigType *t) { - const char *c; + const char *c, *d; c = Char(t); - while (*c) { + d = c + strlen(c); + while (d > c) { if ((*c == '<') && (*(c + 1) == '(')) { int nest = 1; c++; - while (*c && nest) { - if (*c == '<') + while ((d > c) && nest) { + if (*c == '<' && *(c + 1) == '(') nest++; - if (*c == '>') + if (*c == '>' && *(c - 1) == ')') nest--; c++; } @@ -1120,18 +1121,19 @@ String *SwigType_istemplate_only_templateprefix(const SwigType *t) { * ----------------------------------------------------------------------------- */ String *SwigType_templateargs(const SwigType *t) { - const char *c; + const char *c, *d; const char *start; c = Char(t); - while (*c) { + d = c + strlen(c); + while (d > c) { if ((*c == '<') && (*(c + 1) == '(')) { int nest = 1; start = c; c++; - while (*c && nest) { - if (*c == '<') + while ((d > c) && nest) { + if (*c == '<' && *(c + 1) == '(') nest++; - if (*c == '>') + if (*c == '>' && *(c - 1) == ')') nest--; c++; }