I'm trying to port a legacy 32 bit parser code generated from flex.bison. I must use Visual Studio 2019 and compile to x64 target. A crash occures (reading access violation) while parsing the parameters in this code :
case 42:
{ registerTypedef( (yyvsp[(2) - (4)]), (yyvsp[(3) - (4)]) ); }
break;
Here is the called function definition :
void registerTypedef(char* typeref, char* typeName)
{
//SG_TRACE_INFO("registerTypedef %s %s", typeName, typeref);
std::string typeNameStr = typeName;
std::string typeRefStr = typeref;
TheSGFactory::GetInstance().SG_Factory::RegisterTypeDef(typeNameStr, typeRefStr);
The corresponding rule is the following :
declaration_typedef
: TYPEDEF TYPEDEF_NAME IDENTIFIER ';' { registerTypedef( $2, $3 ); }
| TYPEDEF basic_type IDENTIFIER ';' { registerTypedef( $2, $3 ); }
;
It looks like the yyvsp is accessed with negative index (2) - (4) = -2. This should be OK as the same code is working perfectly with 32 bit compiler. The C99 standard seems to be OK with this also.
I have tried to use latest flex/bison versions available under windows and unix. the generated code is quite similar and the issue is the same.
Is there a magic Visual Studio Option to make it accept negative index ? Is there a magic Flex/bison parameter to use that would fix this issue ?
Thanks a lot !