diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-12-14 15:42:26 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-12-14 21:27:03 +0100 |
commit | a8d2cea0a176bc339bbfdbe3f0e608fc88363c2e (patch) | |
tree | 32c49366de369dc56692a2d20eb392d7e1eedf90 /starmath | |
parent | 9b39461a16ddcc53c795bc2308d3ff572264cf3e (diff) |
more leaks with exceptions
Change-Id: I9ace65832d4f8b9a531fddb45a6cea4ad83153ea
Reviewed-on: https://gerrit.libreoffice.org/46464
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/source/parse.cxx | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index c9a6cfdf9c5d..420b8c3d6f67 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -937,6 +937,17 @@ void SmParser::NextToken() m_nBufferIndex = aRes.EndPos; } +namespace +{ + SmNodeArray buildNodeArray(std::vector<std::unique_ptr<SmNode>>& rSubNodes) + { + SmNodeArray aSubArray(rSubNodes.size()); + for (size_t i = 0; i < rSubNodes.size(); ++i) + aSubArray[i] = rSubNodes[i].release(); + return aSubArray; + } +} + // grammar SmTableNode *SmParser::DoTable() @@ -945,16 +956,16 @@ SmTableNode *SmParser::DoTable() if (aDepthGuard.TooDeep()) throw std::range_error("parser depth limit"); - SmNodeArray aLineArray; - aLineArray.push_back(DoLine()); + std::vector<std::unique_ptr<SmNode>> aLineArray; + aLineArray.emplace_back(std::unique_ptr<SmNode>(DoLine())); while (m_aCurToken.eType == TNEWLINE) { NextToken(); - aLineArray.push_back(DoLine()); + aLineArray.emplace_back(std::unique_ptr<SmNode>(DoLine())); } assert(m_aCurToken.eType == TEND); std::unique_ptr<SmTableNode> pSNode(new SmTableNode(m_aCurToken)); - pSNode->SetSubNodes(aLineArray); + pSNode->SetSubNodes(buildNodeArray(aLineArray)); return pSNode.release(); } @@ -995,16 +1006,16 @@ SmLineNode *SmParser::DoLine() if (aDepthGuard.TooDeep()) throw std::range_error("parser depth limit"); - SmNodeArray ExpressionArray; + std::vector<std::unique_ptr<SmNode>> ExpressionArray; // start with single expression that may have an alignment statement // (and go on with expressions that must not have alignment // statements in 'while' loop below. See also 'Expression()'.) if (m_aCurToken.eType != TEND && m_aCurToken.eType != TNEWLINE) - ExpressionArray.push_back(DoAlign()); + ExpressionArray.emplace_back(std::unique_ptr<SmNode>(DoAlign())); while (m_aCurToken.eType != TEND && m_aCurToken.eType != TNEWLINE) - ExpressionArray.push_back(DoExpression()); + ExpressionArray.emplace_back(std::unique_ptr<SmNode>(DoExpression())); //If there's no expression, add an empty one. //this is to avoid a formula tree without any caret @@ -1013,25 +1024,14 @@ SmLineNode *SmParser::DoLine() { SmToken aTok = SmToken(); aTok.eType = TNEWLINE; - ExpressionArray.push_back(new SmExpressionNode(aTok)); + ExpressionArray.emplace_back(std::unique_ptr<SmNode>(new SmExpressionNode(aTok))); } auto pSNode = o3tl::make_unique<SmLineNode>(m_aCurToken); - pSNode->SetSubNodes(ExpressionArray); + pSNode->SetSubNodes(buildNodeArray(ExpressionArray)); return pSNode.release(); } -namespace -{ - SmNodeArray buildNodeArray(std::vector<std::unique_ptr<SmNode>>& rSubNodes) - { - SmNodeArray aSubArray(rSubNodes.size()); - for (size_t i = 0; i < rSubNodes.size(); ++i) - aSubArray[i] = rSubNodes[i].release(); - return aSubArray; - } -} - SmNode *SmParser::DoExpression(bool bUseExtraSpaces) { DepthProtect aDepthGuard(m_nParseDepth); @@ -1270,11 +1270,11 @@ SmNode *SmParser::DoPower() throw std::range_error("parser depth limit"); // get body for sub- supscripts on top of stack - SmNode *pNode = DoTerm(false); + std::unique_ptr<SmNode> xNode(DoTerm(false)); if (m_aCurToken.nGroup == TG::Power) - return DoSubSup(TG::Power, pNode); - return pNode; + return DoSubSup(TG::Power, xNode.release()); + return xNode.release(); } SmBlankNode *SmParser::DoBlank() |