Skip to content
Snippets Groups Projects
Commit 0b9b7045 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by con
Browse files

QmlDesigner.rewriter: crash fix

When pasting or reading in a Component that has no object definition
inside we crashed.

I added an explicit check in the FirstDefinitionFinder.
In the TextToModelMerger we then handle this case.

Task-Nr: QTCREATORBUG-4730
Reviewed-by: Erik Verbruggen
parent 98410507
No related branches found
No related tags found
No related merge requests found
......@@ -54,13 +54,16 @@ FirstDefinitionFinder::FirstDefinitionFinder(const QString &text):
\arg the offset of the object to search in
\return the offset of the first object definition
*/
quint32 FirstDefinitionFinder::operator()(quint32 offset)
qint32 FirstDefinitionFinder::operator()(quint32 offset)
{
m_offset = offset;
m_firstObjectDefinition = 0;
Node::accept(m_doc->qmlProgram(), this);
if (!m_firstObjectDefinition)
return -1;
return m_firstObjectDefinition->firstSourceLocation().offset;
}
......
......@@ -43,7 +43,7 @@ class FirstDefinitionFinder: protected QmlJS::AST::Visitor
public:
FirstDefinitionFinder(const QString &text);
quint32 operator()(quint32 offset);
qint32 operator()(quint32 offset);
protected:
using QmlJS::AST::Visitor::visit;
......
......@@ -1397,6 +1397,10 @@ void TextToModelMerger::setupComponent(const ModelNode &node)
if (componentText.contains("Component")) { //explicit component
FirstDefinitionFinder firstDefinitionFinder(componentText);
int offset = firstDefinitionFinder(0);
if (offset < 0) {
node.variantProperty("__component_data").setValue(QLatin1String(""));
return; //No object definition found
}
ObjectLengthCalculator objectLengthCalculator;
unsigned length;
if (objectLengthCalculator(componentText, offset, length)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment