@@ -13314,25 +13314,25 @@ add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod
1331413314
1331513315 int count = 0 ;
1331613316 MibcGroupMethodEntryState state = FIND_METHOD_TYPE_ENTRY_START ;
13317- uint8_t * cur = ( uint8_t * ) mibcGroupMethodHeader -> code ;
13318- uint8_t * end = ( uint8_t * ) mibcGroupMethodHeader -> code + mibcGroupMethodHeader -> code_size ;
13317+ const unsigned char * cur = mibcGroupMethodHeader -> code ;
13318+ const unsigned char * end = mibcGroupMethodHeader -> code + mibcGroupMethodHeader -> code_size ;
1331913319 while (cur < end ) {
1332013320 MonoOpcodeEnum il_op ;
13321- const unsigned char * opcodeIp = (unsigned char * )cur ;
13322- const unsigned char * opcodeEnd = (unsigned char * )end ;
13323- cur += mono_opcode_value_and_size (& opcodeIp , opcodeEnd , & il_op );
13321+ const int op_size = mono_opcode_value_and_size (& cur , end , & il_op );
1332413322
1332513323 if (state == FIND_METHOD_TYPE_ENTRY_END ) {
1332613324 if (il_op == MONO_CEE_POP )
1332713325 state = FIND_METHOD_TYPE_ENTRY_START ;
13326+ cur += op_size ;
1332813327 continue ;
1332913328 }
1333013329 g_assert (il_op == MONO_CEE_LDTOKEN );
1333113330 state = FIND_METHOD_TYPE_ENTRY_END ;
1333213331
13333- g_assert (opcodeIp + 4 < opcodeEnd );
13334- guint32 mibcGroupMethodEntryToken = read32 (opcodeIp + 1 );
13332+ g_assert (cur + 4 < end ); // Assert that there is atleast a 32 bit token before the end
13333+ guint32 mibcGroupMethodEntryToken = read32 (cur + 1 );
1333513334 g_assertf ((mono_metadata_token_table (mibcGroupMethodEntryToken ) == MONO_TABLE_MEMBERREF || mono_metadata_token_table (mibcGroupMethodEntryToken ) == MONO_TABLE_METHODSPEC ), "token %x is not MemberRef or MethodSpec.\n" , mibcGroupMethodEntryToken );
13335+ cur += op_size ;
1333613336
1333713337 MonoMethod * methodEntry = mono_get_method_checked (image , mibcGroupMethodEntryToken , mibcModuleClass , context , error );
1333813338 mono_error_assert_ok (error );
@@ -13415,24 +13415,26 @@ compatible_mibc_profile_config (MonoImage *image, MonoClass *mibcModuleClass)
1341513415
1341613416 gboolean isConfigCompatible = FALSE;
1341713417 MibcConfigParserState state = PARSING_MIBC_CONFIG_NONE ;
13418- uint8_t * cur = ( uint8_t * ) mibcConfigHeader -> code ;
13419- uint8_t * end = ( uint8_t * ) mibcConfigHeader -> code + mibcConfigHeader -> code_size ;
13420- while (cur < end ) {
13418+ const unsigned char * cur = mibcConfigHeader -> code ;
13419+ const unsigned char * end = mibcConfigHeader -> code + mibcConfigHeader -> code_size ;
13420+ while (cur < end && ! isConfigCompatible ) {
1342113421 MonoOpcodeEnum il_op ;
13422- const unsigned char * opcodeIp = (unsigned char * )cur ;
13423- const unsigned char * opcodeEnd = (unsigned char * )end ;
13424- cur += mono_opcode_value_and_size (& opcodeIp , opcodeEnd , & il_op );
13425- // opcodeIp gets moved to point at end of opcode
13426- // il opcode arg is opcodeIp + 1
13427- // we only care about args of ldstr, which are 32bits/4bytes
13428- if (il_op == MONO_CEE_POP )
13429- continue ;
13422+ const int op_size = mono_opcode_value_and_size (& cur , end , & il_op );
1343013423
13424+ // MibcConfig ends with a Ret
1343113425 if (il_op == MONO_CEE_RET )
1343213426 break ;
1343313427
13434- g_assert (opcodeIp + 4 < opcodeEnd );
13435- guint32 token = read32 (opcodeIp + 1 );
13428+ // we only care about args of ldstr, which are 32bits/4bytes
13429+ // ldstr arg is cur + 1
13430+ if (il_op != MONO_CEE_LDSTR ) {
13431+ cur += op_size ;
13432+ continue ;
13433+ }
13434+
13435+ g_assert (cur + 4 < end ); // Assert that there is atleast a 32 bit token before the end
13436+ guint32 token = read32 (cur + 1 );
13437+ cur += op_size ;
1343613438
1343713439 char * value = mono_ldstr_utf8 (image , mono_metadata_token_index (token ), error );
1343813440 mono_error_assert_ok (error );
@@ -13504,21 +13506,22 @@ add_mibc_profile_methods (MonoAotCompile *acfg, char *filename)
1350413506 mono_error_assert_ok (error );
1350513507
1350613508 int count = 0 ;
13507- uint8_t * cur = ( uint8_t * ) header -> code ;
13508- uint8_t * end = ( uint8_t * ) header -> code + header -> code_size ;
13509+ const unsigned char * cur = header -> code ;
13510+ const unsigned char * end = header -> code + header -> code_size ;
1350913511 while (cur < end ) {
1351013512 MonoOpcodeEnum il_op ;
13511- const unsigned char * opcodeIp = (unsigned char * )cur ;
13512- const unsigned char * opcodeEnd = (unsigned char * )end ;
13513- cur += mono_opcode_value_and_size (& opcodeIp , opcodeEnd , & il_op );
13514- // opcodeIp gets moved to point at end of opcode
13515- // il opcode arg is opcodeIp + 1
13513+ const int op_size = mono_opcode_value_and_size (& cur , end , & il_op );
13514+
1351613515 // we only care about args of ldtoken's, which are 32bits/4bytes
13517- if (il_op != MONO_CEE_LDTOKEN )
13516+ // ldtoken arg is cur + 1
13517+ if (il_op != MONO_CEE_LDTOKEN ) {
13518+ cur += op_size ;
1351813519 continue ;
13520+ }
1351913521
13520- g_assert (opcodeIp + 4 < opcodeEnd );
13521- guint32 token = read32 (opcodeIp + 1 );
13522+ g_assert (cur + 4 < end ); // Assert that there is atleast a 32 bit token before the end
13523+ guint32 token = read32 (cur + 1 );
13524+ cur += op_size ;
1352213525
1352313526 MonoMethod * mibcGroupMethod = mono_get_method_checked (image , token , mibcModuleClass , context , error );
1352413527 mono_error_assert_ok (error );
0 commit comments