vm: Fix potential crash in <word> primitive if profiling is enabled

db4
Slava Pestov 2009-09-24 04:31:11 -05:00
parent 1b84f179cd
commit 576e725662
2 changed files with 12 additions and 1 deletions

View File

@ -59,3 +59,8 @@ words ;
[ ] [ [ [ ] compile-call ] profile ] unit-test [ ] [ [ [ ] compile-call ] profile ] unit-test
[ [ gensym execute ] profile ] [ T{ undefined } = ] must-fail-with [ [ gensym execute ] profile ] [ T{ undefined } = ] must-fail-with
: crash-bug-1 ( -- x ) "hi" "bye" <word> ;
: crash-bug-2 ( -- ) 100000 [ crash-bug-1 drop ] times ;
[ ] [ [ crash-bug-2 ] profile ] unit-test

View File

@ -66,7 +66,13 @@ void factorvm::update_word_xt(cell w_)
if(profiling_p) if(profiling_p)
{ {
if(!w->profiling) if(!w->profiling)
w->profiling = compile_profiling_stub(w.value()); {
/* Note: can't do w->profiling = ... since if LHS
evaluates before RHS, since in that case if RHS does a
GC, we will have an invalid pointer on the LHS */
code_block *profiling = compile_profiling_stub(w.value());
w->profiling = profiling;
}
w->xt = w->profiling->xt(); w->xt = w->profiling->xt();
} }