From fd4699533caa83a3a08e9e17beed1bd3fb1e6b1d Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 22 Jul 2011 07:57:30 +0000 Subject: [PATCH] 2011-07-22 09:57 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/vm/hvm.c ! added protection against self-recursive iterating in code like: FOR EACH var in @var [...] NEXT Now RTE is generated in such case instead of GPF --- harbour/ChangeLog | 8 ++++++++ harbour/src/vm/hvm.c | 16 ++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4948a08f46..3b63edf837 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,14 @@ The license applies to all entries newer than 2009-04-28. */ +2011-07-22 09:57 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/vm/hvm.c + ! added protection against self-recursive iterating in code like: + FOR EACH var in @var + [...] + NEXT + Now RTE is generated in such case instead of GPF + 2011-07-21 01:27 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * INSTALL ! typo diff --git a/harbour/src/vm/hvm.c b/harbour/src/vm/hvm.c index 6b6681de69..3d13a76d0a 100644 --- a/harbour/src/vm/hvm.c +++ b/harbour/src/vm/hvm.c @@ -4621,7 +4621,6 @@ static void hb_vmEnumStart( int nVars, int nDescend ) pValue = hb_stackItemFromTop( -i ); /* create extended reference for enumerator destructor */ hb_vmEnumReference( pValue ); - pBase = &( ( PHB_ENUMREF ) pValue->item.asExtRef.value )->basevalue; /* store the reference to control variable */ pEnumRef = hb_stackItemFromTop( -i + 1 ); hb_itemCopy( &( ( PHB_ENUMREF ) pValue->item.asExtRef.value )->enumref, @@ -4631,14 +4630,19 @@ static void hb_vmEnumStart( int nVars, int nDescend ) /* store the old value of control variable and clear it */ hb_itemMove( &( ( PHB_ENUMREF ) pValue->item.asExtRef.value )->oldvalue, pEnum ); - /* set the iterator value */ - pEnum->type = HB_IT_BYREF | HB_IT_ENUM; - pEnum->item.asEnum.basePtr = pBase; - pEnum->item.asEnum.valuePtr = NULL; + pBase = &( ( PHB_ENUMREF ) pValue->item.asExtRef.value )->basevalue; if( HB_IS_BYREF( pBase ) ) pBase = hb_itemUnRef( pBase ); + if( HB_IS_COMPLEX( pEnum ) ) + hb_itemClear( pEnum ); + + /* set the iterator value */ + pEnum->type = HB_IT_BYREF | HB_IT_ENUM; + pEnum->item.asEnum.basePtr = &( ( PHB_ENUMREF ) pValue->item.asExtRef.value )->basevalue; + pEnum->item.asEnum.valuePtr = NULL; + if( HB_IS_OBJECT( pBase ) && hb_objHasOperator( pBase, HB_OO_OP_ENUMSTART ) ) { pEnum->item.asEnum.offset = 0; @@ -4687,7 +4691,7 @@ static void hb_vmEnumStart( int nVars, int nDescend ) else fStart = HB_FALSE; } - else + else if( hb_vmRequestQuery() == 0 ) { hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ), 1, pBase ); return;