diff options
author | John Hodge <tpg@mutabah.net> | 2016-07-07 04:53:45 +1000 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-07-07 04:53:45 +1000 |
commit | ddb32569d7a42bcb440cd7ddc7add13654070c80 (patch) | |
tree | 6dbc15e513dda22b69f7da7a342d558595e76813 /src | |
parent | 860251fe792c784a3733a39f401a5b2fe0e148ad (diff) | |
download | mrust-ddb32569d7a42bcb440cd7ddc7add13654070c80.tar.gz |
HIR Typecheck CS - Store clones of possible ivar types (prevents use-after-free)
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 01cefa0c..bcaf3a68 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -54,7 +54,8 @@ struct Context struct IVarPossible { // TODO: If an ivar is eliminated (i.e. has its type dropped) while its pointer is here - things will break - ::std::vector<const ::HIR::TypeRef*> types; + //::std::vector<const ::HIR::TypeRef*> types; + ::std::vector<::HIR::TypeRef> types; }; const ::HIR::Crate& m_crate; @@ -2078,7 +2079,8 @@ void Context::possible_equate_type(unsigned int ivar_index, const ::HIR::TypeRef if( ivar_index >= possible_ivar_vals.size() ) { possible_ivar_vals.resize( ivar_index + 1 ); } - possible_ivar_vals[ivar_index].types.push_back( &t ); + //possible_ivar_vals[ivar_index].types.push_back( &t ); + possible_ivar_vals[ivar_index].types.push_back( t.clone() ); } void Context::add_var(unsigned int index, const ::std::string& name, ::HIR::TypeRef type) { @@ -2635,7 +2637,8 @@ void Typecheck_Code_CS(const typeck::ModuleState& ms, t_args& args, const ::HIR: { bool found = false; for( auto it2 = ivar_ent.types.begin(); it2 != it; ++ it2 ) { - if( context.m_ivars.types_equal( **it, **it2 ) ) { + //if( context.m_ivars.types_equal( **it, **it2 ) ) { + if( context.m_ivars.types_equal( *it, *it2 ) ) { found = true; break; } @@ -2660,7 +2663,8 @@ void Typecheck_Code_CS(const typeck::ModuleState& ms, t_args& args, const ::HIR: DEBUG("- IVar " << ty_l << " had possibilities, but was known"); } else if( ivar_ent.types.size() == 1 ) { - const ::HIR::TypeRef& ty_r = *ivar_ent.types[0]; + //const ::HIR::TypeRef& ty_r = ivar_ent.types[0]; + const ::HIR::TypeRef& ty_r = ivar_ent.types[0]; // Only one possibility DEBUG("- IVar " << ty_l << " = " << ty_r); context.equate_types(Span(), ty_l, ty_r); |