Skip to content

Conversation

@kvarec
Copy link
Contributor

@kvarec kvarec commented Nov 23, 2021

Fix assertion for XML document with elements, but without documentElement.

@rleigh-codelibre
Copy link
Contributor

Would it be possible to provide a small self-contained example which triggers the assertion?

@kvarec
Copy link
Contributor Author

kvarec commented Nov 24, 2021

Ok, I will try to do it.

@kvarec
Copy link
Contributor Author

kvarec commented Nov 24, 2021

Example1.cpp

#include <xalanc/Include/PlatformDefinitions.hpp>

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/impl/DOMDocumentImpl.hpp>

#include <xalanc/XPath/XPathEvaluator.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
#include <xalanc/XercesParserLiaison/XercesDocumentWrapper.hpp>

int main()
{
    using xercesc::XMLPlatformUtils;
    using xalanc::XPathEvaluator;

    XMLPlatformUtils::Initialize();
    XPathEvaluator::initialize();
    {
        using xalanc::XalanDOMString;
        using xalanc::XalanSourceTreeInit;
        using xalanc::XalanSourceTreeDOMSupport;
        using xalanc::XalanSourceTreeParserLiaison;
        using xalanc::XalanElement;
        using xalanc::XPath;
        using xalanc::XalanNode;

        XalanSourceTreeInit theSourceTreeInit;
        XalanSourceTreeDOMSupport theDOMSupport;
        XalanSourceTreeParserLiaison theLiaison(theDOMSupport);

        theDOMSupport.setParserLiaison(&theLiaison);
        
        XalanElement* theContextNode = 0;
        {
            using namespace xercesc;
            using xalanc::XercesDocumentWrapper;

            DOMImplementation* theDOMImpl = DOMImplementation::getImplementation();
            DOMDocument* theDocument = theDOMImpl->createDocument();
            DOMNode *theNode = theDocument->createElement(XalanDOMString("NODE").c_str());
           
            MemoryManager* theManager = GET_DIRECT_MM(theDocument);
            auto theWrapper = XercesDocumentWrapper::create(*theManager, theDocument, false, false, false);

            theContextNode = static_cast<XalanElement*>(theWrapper->mapNode(theNode));
        }

        XPathEvaluator().selectSingleNode(
                theDOMSupport,
                theContextNode,
                XalanDOMString("//NODE").c_str());
    }

    XPathEvaluator::terminate();
    XMLPlatformUtils::Terminate();

    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.2)

project(example1 CXX)

find_package(XercesC REQUIRED)
find_package(XalanC REQUIRED)

include_directories(
  ${XercesC_INCLUDE_DIRS}
  ${XalanC_INCLUDE_DIRS}
)

add_executable(${PROJECT_NAME}
  Example1.cpp
)

target_link_libraries(${PROJECT_NAME}
  ${XercesC_LIBRARIES}
  ${XalanC_LIBRARIES}
)

Move CmakeLists.txt and Example1.cpp to somw dir (for example named "src") and execute:
cmake src && make && ./example1

From gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff79d6cb6 in xalanc_1_11::XPath::findRoot(xalanc_1_11::XPathExecutionContext&, xalanc_1_11::XalanNode*, int const*, int, xalanc_1_11::MutableNodeRefList&) const () from /lib/x86_64-linux-gnu/libxalan-c.so.111
(gdb) bt
#0  0x00007ffff79d6cb6 in xalanc_1_11::XPath::findRoot(xalanc_1_11::XPathExecutionContext&, xalanc_1_11::XalanNode*, int const*, int, xalanc_1_11::MutableNodeRefList&) const () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#1  0x00007ffff79dea5a in xalanc_1_11::XPath::step(xalanc_1_11::XPathExecutionContext&, xalanc_1_11::XalanNode*, int const*, xalanc_1_11::MutableNodeRefList&) const () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#2  0x00007ffff79dfd5a in xalanc_1_11::XPath::locationPath(xalanc_1_11::XalanNode*, int const*, xalanc_1_11::XPathExecutionContext&) const () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#3  0x00007ffff79dbaf4 in xalanc_1_11::XPath::executeMore(xalanc_1_11::XalanNode*, int const*, xalanc_1_11::XPathExecutionContext&) const () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#4  0x00007ffff79dc2b7 in xalanc_1_11::XPath::execute(xalanc_1_11::XalanNode*, xalanc_1_11::PrefixResolver const&, xalanc_1_11::XPathExecutionContext&) const () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#5  0x00007ffff79d531e in xalanc_1_11::XPathEvaluator::evaluate(xalanc_1_11::DOMSupport&, xalanc_1_11::XalanNode*, xalanc_1_11::XPath const&, xalanc_1_11::PrefixResolver const&, xalanc_1_11::XPathEnvSupport&) ()
   from /lib/x86_64-linux-gnu/libxalan-c.so.111
#6  0x00007ffff79d5ca1 in xalanc_1_11::XPathEvaluator::evaluate(xalanc_1_11::DOMSupport&, xalanc_1_11::XalanNode*, char16_t const*, xalanc_1_11::PrefixResolver const&, xalanc_1_11::XPathEnvSupport&) ()
   from /lib/x86_64-linux-gnu/libxalan-c.so.111
#7  0x00007ffff79d5deb in xalanc_1_11::XPathEvaluator::evaluate(xalanc_1_11::DOMSupport&, xalanc_1_11::XalanNode*, char16_t const*, xalanc_1_11::XalanElement const*) () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#8  0x00007ffff79d5ea7 in xalanc_1_11::XPathEvaluator::selectSingleNode(xalanc_1_11::DOMSupport&, xalanc_1_11::XalanNode*, char16_t const*, xalanc_1_11::XalanElement const*) () from /lib/x86_64-linux-gnu/libxalan-c.so.111
#9  0x0000555555557640 in main () at /home/user/dev/xalan-c_example1/src/Example1.cpp:50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants