Fix seg fault handling template parameter expressions containing '>='

Similar to previous commit

Issue #1037
This commit is contained in:
William S Fulton 2022-11-22 21:40:38 +00:00
commit ca5c68e544
3 changed files with 14 additions and 14 deletions

View file

@ -8,7 +8,8 @@ Version 4.2.0 (in progress)
=========================== ===========================
2022-11-22: wsfulton 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 2022-11-18: wsfulton
Duplicate class template instantiations via %template now issue a warning and are ignored. Duplicate class template instantiations via %template now issue a warning and are ignored.

View file

@ -44,9 +44,6 @@ void tester() {
template <typename T, std::enable_if_t<sizeof(T) <= 4>> template <typename T, std::enable_if_t<sizeof(T) <= 4>>
void destId(T el) {} void destId(T el) {}
/*
not yet fixed
template <typename T, std::enable_if_t<sizeof(T) >= 3>> template <typename T, std::enable_if_t<sizeof(T) >= 3>>
void destId(const T& el) {} void destId(const T& el) {}
*/
%} %}

View file

@ -1043,16 +1043,17 @@ String *SwigType_templateprefix(const SwigType *t) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
String *SwigType_templatesuffix(const SwigType *t) { String *SwigType_templatesuffix(const SwigType *t) {
const char *c; const char *c, *d;
c = Char(t); c = Char(t);
while (*c) { d = c + strlen(c);
while (d > c) {
if ((*c == '<') && (*(c + 1) == '(')) { if ((*c == '<') && (*(c + 1) == '(')) {
int nest = 1; int nest = 1;
c++; c++;
while (*c && nest) { while ((d > c) && nest) {
if (*c == '<') if (*c == '<' && *(c + 1) == '(')
nest++; nest++;
if (*c == '>') if (*c == '>' && *(c - 1) == ')')
nest--; nest--;
c++; c++;
} }
@ -1120,18 +1121,19 @@ String *SwigType_istemplate_only_templateprefix(const SwigType *t) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
String *SwigType_templateargs(const SwigType *t) { String *SwigType_templateargs(const SwigType *t) {
const char *c; const char *c, *d;
const char *start; const char *start;
c = Char(t); c = Char(t);
while (*c) { d = c + strlen(c);
while (d > c) {
if ((*c == '<') && (*(c + 1) == '(')) { if ((*c == '<') && (*(c + 1) == '(')) {
int nest = 1; int nest = 1;
start = c; start = c;
c++; c++;
while (*c && nest) { while ((d > c) && nest) {
if (*c == '<') if (*c == '<' && *(c + 1) == '(')
nest++; nest++;
if (*c == '>') if (*c == '>' && *(c - 1) == ')')
nest--; nest--;
c++; c++;
} }