diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2015-12-16 18:02:30 +0900 |
---|---|---|
committer | Kohei Yoshida <libreoffice@kohei.us> | 2015-12-23 00:39:56 +0000 |
commit | 4753d78cf93bad974f062d8cfe75b4b610385b7e (patch) | |
tree | 138e05074e45ddd5a3bdaad187820166c3152eca /starmath | |
parent | 27450bc72d88b8490d17cb506f85fb4d838df0ea (diff) |
starmath: Assert that a parent always finds its child
Change-Id: I6cb75e0d62141dba2809aaec62761cedd8c3257a
Reviewed-on: https://gerrit.libreoffice.org/20733
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/cursor.hxx | 5 | ||||
-rw-r--r-- | starmath/source/cursor.cxx | 36 |
2 files changed, 12 insertions, 29 deletions
diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx index 9de6b5309d57..6962cf5d89c3 100644 --- a/starmath/inc/cursor.hxx +++ b/starmath/inc/cursor.hxx @@ -12,6 +12,7 @@ #include "node.hxx" #include "caret.hxx" +#include <cassert> #include <list> #include <memory> @@ -268,8 +269,8 @@ private: SmNode* pNode = rpNode; if(rpNode && rpNode->GetParent()){ //Don't remove this, correctness relies on it int index = rpNode->GetParent()->IndexOfSubNode(rpNode); - if(index != -1) - rpNode->GetParent()->SetSubNode(index, nullptr); + assert(index >= 0); + rpNode->GetParent()->SetSubNode(index, nullptr); } rpNode = nullptr; //Create line from node diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx index 8efa9315ea79..355336cf8b5f 100644 --- a/starmath/source/cursor.cxx +++ b/starmath/source/cursor.cxx @@ -12,6 +12,7 @@ #include "view.hxx" #include "accessibility.hxx" #include <comphelper/string.hxx> +#include <cassert> void SmCursor::Move(OutputDevice* pDev, SmMovementDirection direction, bool bMoveAnchor){ SmCaretPosGraphEntry* NewPos = nullptr; @@ -176,6 +177,7 @@ void SmCursor::DeletePrev(OutputDevice* pDev){ SmNode* pLine = FindTopMostNodeInLine(mpPosition->CaretPos.pSelectedNode); SmStructureNode* pLineParent = pLine->GetParent(); int nLineOffset = pLineParent->IndexOfSubNode(pLine); + assert(nLineOffset >= 0); //If we're in front of a node who's parent is a TABLE if(pLineParent->GetType() == NTABLE && mpPosition->CaretPos.Index == 0 && nLineOffset > 0){ @@ -262,11 +264,7 @@ void SmCursor::Delete(){ SmStructureNode* pLineParent = pLine->GetParent(); //Find line offset in parent int nLineOffset = pLineParent->IndexOfSubNode(pLine); - if (nLineOffset == -1) - { - SAL_WARN("starmath", "pLine must be a child of its parent!"); - return; - } + assert(nLineOffset >= 0); //Position after delete SmCaretPos PosAfterDelete; @@ -304,12 +302,7 @@ void SmCursor::InsertNodes(SmNodeList* pNewNodes){ //Find line parent and line index in parent SmStructureNode* pLineParent = pLine->GetParent(); int nParentIndex = pLineParent->IndexOfSubNode(pLine); - OSL_ENSURE(nParentIndex != -1, "pLine must be a subnode of pLineParent!"); - if (nParentIndex == -1) - { - delete pNewNodes; - return; - } + assert(nParentIndex >= 0); //Convert line to list SmNodeList* pLineList = NodeToList(pLine); @@ -506,7 +499,7 @@ void SmCursor::InsertSubSup(SmSubSup eSubSup) { //Find Parent and offset in parent SmStructureNode *pLineParent = pLine->GetParent(); int nParentIndex = pLineParent->IndexOfSubNode(pLine); - OSL_ENSURE(nParentIndex != -1, "pLine must be a subnode of pLineParent!"); + assert(nParentIndex >= 0); //TODO: Consider handling special cases where parent is an SmOperNode, // Maybe this method should be able to add limits to an SmOperNode... @@ -677,9 +670,7 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) { //Find parent and offset in parent SmStructureNode *pLineParent = pLine->GetParent(); int nParentIndex = pLineParent->IndexOfSubNode(pLine); - OSL_ENSURE( nParentIndex != -1, "pLine must be a subnode of pLineParent!"); - if (nParentIndex < 0) - return; + assert(nParentIndex >= 0); //Convert line to list SmNodeList *pLineList = NodeToList(pLine); @@ -814,12 +805,7 @@ bool SmCursor::InsertRow() { //Find parent and offset in parent SmStructureNode *pLineParent = pLine->GetParent(); int nParentIndex = pLineParent->IndexOfSubNode(pLine); - - if (nParentIndex == -1) - { - SAL_WARN("starmath", "pLine must be a subnode of pLineParent!"); - return false; - } + assert(nParentIndex >= 0); //Discover the context of this command SmTableNode *pTable = nullptr; @@ -834,7 +820,7 @@ bool SmCursor::InsertRow() { //NOTE: This hack might give problems if we stop ignoring SmAlignNode pTable = static_cast<SmTableNode*>(pLineParent->GetParent()); nTableIndex = pTable->IndexOfSubNode(pLineParent); - OSL_ENSURE(nTableIndex != -1, "pLineParent must be a child of its parent!"); + assert(nTableIndex >= 0); } if(pLineParent->GetType() == NMATRIX) pMatrix = static_cast<SmMatrixNode*>(pLineParent); @@ -938,11 +924,7 @@ void SmCursor::InsertFraction() { //Find Parent and offset in parent SmStructureNode *pLineParent = pLine->GetParent(); int nParentIndex = pLineParent->IndexOfSubNode(pLine); - if (nParentIndex == -1) - { - SAL_WARN("starmath", "pLine must be a subnode of pLineParent!"); - return; - } + assert(nParentIndex >= 0); //We begin modifying the tree here BeginEdit(); |