Fix undefined behaviour in parser

Fix undefined behaviour in swig's parser when handling default parameter
expressions containing method calls.

Fixes #2447
This commit is contained in:
Olly Betts 2022-11-25 09:51:58 +13:00
commit 81c6a63898
3 changed files with 11 additions and 5 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.2.0 (in progress)
===========================
2022-11-25: olly
#2447 Fix undefined behaviour in swig's parser when handling
default parameter expressions containing method calls.
2022-11-22: wsfulton
#1037 Fix seg fault handling template parameter expressions containing '<='
or '>='.

View file

@ -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()) {}
%}

View file

@ -6582,7 +6582,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 {
@ -6591,14 +6591,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 {
@ -6607,7 +6607,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);
}
;