summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2022-11-25 09:51:58 +1300
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-11-26 10:33:15 +0000
commitedec8f0e6557777e9731245ba2cf8282110de33c (patch)
tree2bef429c099ad78933967625b35e750f35a43de3
parentc3a7168541d61e3b5e2c2d59215917ccab358683 (diff)
downloadswig-edec8f0e6557777e9731245ba2cf8282110de33c.tar.gz
Fix undefined behaviour in parser
Fix undefined behaviour in swig's parser when handling default parameter expressions containing method calls. Fixes #2447 Conflicts: CHANGES.current
-rw-r--r--CHANGES.current4
-rw-r--r--Examples/test-suite/default_arg_expressions.i4
-rw-r--r--Source/CParse/parser.y8
3 files changed, 11 insertions, 5 deletions
diff --git a/CHANGES.current b/CHANGES.current
index e92b28266..d992157b8 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.1 (in progress)
===========================
+2022-11-25: olly
+ #2447 Fix undefined behaviour in swig's parser when handling
+ default parameter expressions containing method calls.
+
2022-11-05: wsfulton
#2417 Fix -swiglib for Windows when building with CMake.
diff --git a/Examples/test-suite/default_arg_expressions.i b/Examples/test-suite/default_arg_expressions.i
index 99d54c3b9..ce4d3f4a1 100644
--- a/Examples/test-suite/default_arg_expressions.i
+++ b/Examples/test-suite/default_arg_expressions.i
@@ -29,7 +29,7 @@ struct TfToken {
struct Tokens {
const TfToken face;
const TfToken *pface;
- const TfToken& g_face() const { return face; }
+ const TfToken& g_face(int = 0, int = 0) const { return face; }
const TfToken* g_pface() const { return pface; }
Tokens() : face(), pface(&face) {}
};
@@ -68,4 +68,6 @@ void CreateMaterialBindSubsetu(int num = UsdGeomTokensPtr->g_pface()->g_val().g_
void CreateMaterialBindSubsetv(int num = UsdGeomTokensPtr->g_pface()->g_ptr()->g_val()) {}
void CreateMaterialBindSubsetw(int num = UsdGeomTokensPtr->g_face().g_val().g_val()) {}
void CreateMaterialBindSubsetx(int num = UsdGeomTokens.g_face().g_val().g_val()) {}
+void CreateMaterialBindSubsety(int num = UsdGeomTokens.g_face(1).g_val().g_val()) {}
+void CreateMaterialBindSubsetz(int num = UsdGeomTokens.g_face(1,2).g_val().g_val()) {}
%}
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 7f685e84e..6dbdc46c5 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -6581,7 +6581,7 @@ exprmem : ID ARROW ID {
$$.type = 0;
}
| ID ARROW ID LPAREN callparms RPAREN {
- $$.val = NewStringf("%s->%s(%s)", $1, $3, $5);
+ $$.val = NewStringf("%s->%s(%s)", $1, $3, $5.val);
$$.type = 0;
}
| exprmem ARROW ID {
@@ -6590,14 +6590,14 @@ exprmem : ID ARROW ID {
}
| exprmem ARROW ID LPAREN callparms RPAREN {
$$ = $1;
- Printf($$.val, "->%s(%s)", $3, $5);
+ Printf($$.val, "->%s(%s)", $3, $5.val);
}
| ID PERIOD ID {
$$.val = NewStringf("%s.%s", $1, $3);
$$.type = 0;
}
| ID PERIOD ID LPAREN callparms RPAREN {
- $$.val = NewStringf("%s.%s(%s)", $1, $3, $5);
+ $$.val = NewStringf("%s.%s(%s)", $1, $3, $5.val);
$$.type = 0;
}
| exprmem PERIOD ID {
@@ -6606,7 +6606,7 @@ exprmem : ID ARROW ID {
}
| exprmem PERIOD ID LPAREN callparms RPAREN {
$$ = $1;
- Printf($$.val, ".%s(%s)", $3, $5);
+ Printf($$.val, ".%s(%s)", $3, $5.val);
}
;