You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Jon Iles <jo...@packwood-cottages.freeserve.co.uk> on 2000/09/22 10:28:10 UTC

Xalan C++ FunctionNormalize.hpp bug (and fix!)

[Hi there, this is a repost, as I'm not sure that the first mail hit the
list]

I believe I have found a bug in the current version of Xalan C++. It appears
to be present in both the latest distribution, and also in the latest CVS
sources.

In src/XPath/FunctionNormalize.hpp at line 164 in the latest CVS source, the
following code appears.

  if (isSpace(theVector.back()) == true)
  {
   // The last character is a space, so remove it
   theVector.pop_back();
  }

Where the text being passed in contains only whitespace characters, the
vector does not get populated and remains in an uninitialised state. In this
instance I believe that the call to back produces undefined results, and so
it seems to on my platform as the result of the operation is treated as
whitespace, pop_back is called and the vector ends up with its tail before
its head... causing a nasty crash when creating the result string from the
contents of the vector. Can I suggest the following change:

  if (theVector.empty() == false && isSpace(theVector.back()) == true)
  {
   // The last character is a space, so remove it
   theVector.pop_back();
  }

For the record, I working with Xalan under Win32, using MSVC 6 SP4. I am
using STLport 4.0 in place of the MSVC standard C++ library. In this
instance Xalan has been rebuilt from source to use STLport.

Cheers,

Jon