add checks to optional fields in SvXMLImportContext
so when I convert ImportContext to FastParser APIs I don't accidentally rely on data that is not there Change-Id: If4700c7902e11f98a57542943f6a198822689df8 Reviewed-on: https://gerrit.libreoffice.org/85622 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -51,6 +51,7 @@ class XMLOFF_DLLPUBLIC SvXMLImportContext : public css::xml::sax::XFastContextHa
|
||||
SvXMLImport& mrImport;
|
||||
sal_uInt16 mnPrefix;
|
||||
OUString maLocalName;
|
||||
bool mbPrefixAndLocalNameFilledIn;
|
||||
std::unique_ptr<SvXMLNamespaceMap> m_pRewindMap;
|
||||
|
||||
SAL_DLLPRIVATE std::unique_ptr<SvXMLNamespaceMap> TakeRewindMap() { return std::move(m_pRewindMap); }
|
||||
@@ -63,8 +64,9 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
sal_uInt16 GetPrefix() const { return mnPrefix; }
|
||||
const OUString& GetLocalName() const { return maLocalName; }
|
||||
bool IsPrefixFilledIn() const { return mnPrefix != 0; }
|
||||
sal_uInt16 GetPrefix() const { assert(mbPrefixAndLocalNameFilledIn && "those fields not filled, probably fast-parser context"); return mnPrefix; }
|
||||
const OUString& GetLocalName() const { assert(mbPrefixAndLocalNameFilledIn && "those fields not filled, probably fast-parser context"); return maLocalName; }
|
||||
|
||||
/** A contexts constructor does anything that is required if an element
|
||||
* starts. Namespace processing has been done already.
|
||||
|
@@ -244,7 +244,7 @@ SvXMLImportContextRef SwXMLDocContext_Impl::CreateChildContext(
|
||||
break;
|
||||
case XML_TOK_DOC_AUTOSTYLES:
|
||||
// don't use the autostyles from the styles-document for the progress
|
||||
if ( ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
|
||||
if ( !IsPrefixFilledIn() || ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
|
||||
GetSwImport().GetProgressBarHelper()->Increment
|
||||
( PROGRESS_BAR_STEP );
|
||||
pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
|
||||
|
@@ -32,13 +32,16 @@ SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp, sal_uInt16 nPrfx,
|
||||
, mrImport(rImp)
|
||||
, mnPrefix(nPrfx)
|
||||
, maLocalName(rLName)
|
||||
, mbPrefixAndLocalNameFilledIn(true)
|
||||
{
|
||||
assert(!rLName.isEmpty());
|
||||
}
|
||||
|
||||
SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp )
|
||||
: m_nRefCount(0)
|
||||
, mrImport(rImp)
|
||||
, mnPrefix(0)
|
||||
, mbPrefixAndLocalNameFilledIn(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -729,7 +729,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
|
||||
if(!maContexts.empty())
|
||||
{
|
||||
xContext = maContexts.top()->CreateChildContext(nPrefix, aLocalName, xAttrList);
|
||||
SAL_WARN_IF( !xContext.is() || (xContext->GetPrefix() != nPrefix), "xmloff.core",
|
||||
SAL_WARN_IF( xContext.is() && xContext->IsPrefixFilledIn() && (xContext->GetPrefix() != nPrefix), "xmloff.core",
|
||||
"SvXMLImport::startElement: created context has wrong prefix" );
|
||||
}
|
||||
else
|
||||
@@ -782,7 +782,7 @@ rName
|
||||
|
||||
#ifdef DBG_UTIL
|
||||
// Non product only: check if endElement call matches startELement call.
|
||||
if (!xContext->GetLocalName().isEmpty()) // prefix+localname are only valid in the non-FastParser case
|
||||
if (xContext->IsPrefixFilledIn()) // prefix+localname are only valid in the non-FastParser case
|
||||
{
|
||||
OUString aLocalName;
|
||||
sal_uInt16 nPrefix =
|
||||
|
Reference in New Issue
Block a user