[Libreoffice-commits] core.git: 2 commits - starmath/source
Caolán McNamara
caolanm at redhat.com
Thu Dec 14 20:33:29 UTC 2017
starmath/source/parse.cxx | 82 +++++++++++++++++++++++-----------------------
1 file changed, 41 insertions(+), 41 deletions(-)
New commits:
commit d6e97bd2424ab3547726b000cd2181bbd78fc131
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu Dec 14 14:30:47 2017 +0000
ofz#4641 fix leaks with exceptions
Change-Id: I5326240fe79a5752e19d4be3032c5ced70845437
Reviewed-on: https://gerrit.libreoffice.org/46459
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 420b8c3d6f67..57344e1c6ffe 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1045,10 +1045,10 @@ SmNode *SmParser::DoExpression(bool bUseExtraSpaces)
if (RelationArray.size() > 1)
{
- std::unique_ptr<SmExpressionNode> pSNode(new SmExpressionNode(m_aCurToken));
- pSNode->SetSubNodes(buildNodeArray(RelationArray));
- pSNode->SetUseExtraSpaces(bUseExtraSpaces);
- return pSNode.release();
+ std::unique_ptr<SmExpressionNode> xSNode(new SmExpressionNode(m_aCurToken));
+ xSNode->SetSubNodes(buildNodeArray(RelationArray));
+ xSNode->SetUseExtraSpaces(bUseExtraSpaces);
+ return xSNode.release();
}
else
{
@@ -1063,16 +1063,16 @@ SmNode *SmParser::DoRelation()
if (aDepthGuard.TooDeep())
throw std::range_error("parser depth limit");
- SmNode *pFirst = DoSum();
+ std::unique_ptr<SmNode> xFirst(DoSum());
while (TokenInGroup(TG::Relation))
{
- std::unique_ptr<SmStructureNode> pSNode(new SmBinHorNode(m_aCurToken));
- SmNode *pSecond = DoOpSubSup();
- SmNode *pThird = DoSum();
- pSNode->SetSubNodes(pFirst, pSecond, pThird);
- pFirst = pSNode.release();
+ std::unique_ptr<SmStructureNode> xSNode(new SmBinHorNode(m_aCurToken));
+ std::unique_ptr<SmNode> xSecond(DoOpSubSup());
+ std::unique_ptr<SmNode> xThird(DoSum());
+ xSNode->SetSubNodes(xFirst.release(), xSecond.release(), xThird.release());
+ xFirst = std::move(xSNode);
}
- return pFirst;
+ return xFirst.release();
}
SmNode *SmParser::DoSum()
@@ -1493,21 +1493,21 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent)
if ( TokenInGroup(TG::Attribute) ||
TokenInGroup(TG::FontAttr) )
{
- std::stack<SmStructureNode *> aStack;
+ std::stack<std::unique_ptr<SmStructureNode>> aStack;
bool bIsAttr;
while ( (bIsAttr = TokenInGroup(TG::Attribute))
|| TokenInGroup(TG::FontAttr))
- aStack.push(bIsAttr ? DoAttribut() : DoFontAttribut());
+ aStack.push(std::unique_ptr<SmStructureNode>(bIsAttr ? DoAttribut() : DoFontAttribut()));
- SmNode *pFirstNode = DoPower();
+ std::unique_ptr<SmNode> xFirstNode(DoPower());
while (!aStack.empty())
{
- SmStructureNode *pNode = aStack.top();
+ std::unique_ptr<SmStructureNode> xNode = std::move(aStack.top());
aStack.pop();
- pNode->SetSubNodes(nullptr, pFirstNode);
- pFirstNode = pNode;
+ xNode->SetSubNodes(nullptr, xFirstNode.release());
+ xFirstNode = std::move(xNode);
}
- return pFirstNode;
+ return xFirstNode.release();
}
if (TokenInGroup(TG::Function))
return DoFunction();
commit a8d2cea0a176bc339bbfdbe3f0e608fc88363c2e
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu Dec 14 15:42:26 2017 +0000
more leaks with exceptions
Change-Id: I9ace65832d4f8b9a531fddb45a6cea4ad83153ea
Reviewed-on: https://gerrit.libreoffice.org/46464
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
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()
More information about the Libreoffice-commits
mailing list