You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/12/20 05:20:52 UTC

cvs commit: xml-xalan/c/src/XSLT VariablesStack.cpp VariablesStack.hpp

dbertoni    01/12/19 20:20:52

  Modified:    c/src/XSLT VariablesStack.cpp VariablesStack.hpp
  Log:
  Detect when a variable is circularly defined.
  
  Revision  Changes    Path
  1.21      +22 -1     xml-xalan/c/src/XSLT/VariablesStack.cpp
  
  Index: VariablesStack.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/VariablesStack.cpp,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- VariablesStack.cpp	2001/09/26 21:30:23	1.20
  +++ VariablesStack.cpp	2001/12/20 04:20:52	1.21
  @@ -75,7 +75,8 @@
   	m_stack(),
   	m_globalStackFrameIndex(-1),
   	m_globalStackFrameMarked(false),
  -	m_currentStackFrameIndex(0)
  +	m_currentStackFrameIndex(0),
  +	m_guardStack()
   {
   	m_stack.reserve(eDefaultStackSize);
   }
  @@ -97,6 +98,7 @@
   	}
   
   	m_stack.clear();
  +	m_guardStack.clear();
   
   	m_globalStackFrameMarked = false;
   	m_globalStackFrameIndex = -1;
  @@ -413,6 +415,21 @@
   				XalanNode* const	doc = executionContext.getRootDocument();
   				assert(doc != 0);
   
  +#if !defined (XALAN_NO_NAMESPACES)
  +				using std::find;
  +#endif
  +
  +				// See if the ElemVariable instance is already being evaluated...
  +				if (find(m_guardStack.begin(), m_guardStack.end(), var) != m_guardStack.end())
  +				{
  +					executionContext.error(
  +						"A circular variable definition was detected",
  +						doc,
  +						var->getLocator());
  +				}
  +
  +				m_guardStack.push_back(var);
  +
   				// We need to set up a stack frame for the variable's execution...
   				typedef StylesheetExecutionContext::PushAndPopContextMarker	PushAndPopContextMarker;
   
  @@ -420,6 +437,10 @@
   
   				theNewValue = var->getValue(executionContext, doc);
   				assert(theNewValue.null() == false);
  +
  +				assert(m_guardStack.empty() == false);
  +
  +				m_guardStack.pop_back();
   
   				theEntry->setValue(theNewValue);
   				theEntry->activate();
  
  
  
  1.15      +14 -5     xml-xalan/c/src/XSLT/VariablesStack.hpp
  
  Index: VariablesStack.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/VariablesStack.hpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- VariablesStack.hpp	2001/08/13 17:08:54	1.14
  +++ VariablesStack.hpp	2001/12/20 04:20:52	1.15
  @@ -176,8 +176,10 @@
   
   #if defined(XALAN_NO_NAMESPACES)
   	typedef vector<ParamsVectorEntry>		ParamsVectorType;
  +	typedef vector<const ElemVariable*>		RecursionGuardStackType;
   #else
  -	typedef std::vector<ParamsVectorEntry>	ParamsVectorType;
  +	typedef std::vector<ParamsVectorEntry>		ParamsVectorType;
  +	typedef std::vector<const ElemVariable*>	RecursionGuardStackType;
   #endif
   
   	/**
  @@ -569,18 +571,25 @@
   			bool				fSearchGlobalSpace);
   
   
  -	VariableStackStackType	m_stack;
  +	VariableStackStackType		m_stack;
   
  -	int						m_globalStackFrameIndex;
  +	int							m_globalStackFrameIndex;
   
  -	bool					m_globalStackFrameMarked;
  +	bool						m_globalStackFrameMarked;
   
   	/**
   	 * This is the top of the stack frame from where a search 
   	 * for a variable or param should take place.  It may not 
   	 * be the real stack top.
   	 */
  -	unsigned int			m_currentStackFrameIndex;	
  +	unsigned int				m_currentStackFrameIndex;	
  +
  +	/**
  +	 * This will be a stack for any variable definitions
  +	 * that are being evaluated dynamically, to protect
  +	 * against circular definitions.
  +	 */
  +	RecursionGuardStackType		m_guardStack;
   };
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org