Kaydet (Commit) 95d47fbf authored tarafından Takeshi Abe's avatar Takeshi Abe

starmath: SmCaretPos's index must be non-negative

Change-Id: I69a2fc0c9ccaa76a0d93127ac6a1544fe9924605
Reviewed-on: https://gerrit.libreoffice.org/32444Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTakeshi Abe <tabe@fixedpoint.jp>
üst e899b893
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "node.hxx" #include "node.hxx"
#include <cassert>
#include <memory> #include <memory>
#include <vector> #include <vector>
...@@ -24,10 +25,13 @@ struct SmCaretPos{ ...@@ -24,10 +25,13 @@ struct SmCaretPos{
: pSelectedNode(selectedNode) : pSelectedNode(selectedNode)
, nIndex(iIndex) , nIndex(iIndex)
{ {
assert(nIndex >= 0);
} }
/** Selected node */ /** Selected node */
SmNode* pSelectedNode; SmNode* pSelectedNode;
/** Index within the selected node
/** Index (invariant: non-negative) within the selected node
* *
* 0: Position in front of a node * 0: Position in front of a node
* 1: Position after a node or after first char in SmTextNode * 1: Position after a node or after first char in SmTextNode
...@@ -38,6 +42,7 @@ struct SmCaretPos{ ...@@ -38,6 +42,7 @@ struct SmCaretPos{
//TODO: Special cases for SmBlankNode is needed //TODO: Special cases for SmBlankNode is needed
//TODO: Consider forgetting about the todo above... As it's really unpleasant. //TODO: Consider forgetting about the todo above... As it's really unpleasant.
int nIndex; int nIndex;
/** True, if this is a valid caret position */ /** True, if this is a valid caret position */
bool IsValid() const { return pSelectedNode != nullptr; } bool IsValid() const { return pSelectedNode != nullptr; }
bool operator==(const SmCaretPos &pos) const { bool operator==(const SmCaretPos &pos) const {
......
...@@ -17,7 +17,7 @@ SmCaretPosGraph::~SmCaretPosGraph() = default; ...@@ -17,7 +17,7 @@ SmCaretPosGraph::~SmCaretPosGraph() = default;
SmCaretPosGraphEntry* SmCaretPosGraph::Add(SmCaretPos pos, SmCaretPosGraphEntry* SmCaretPosGraph::Add(SmCaretPos pos,
SmCaretPosGraphEntry* left) SmCaretPosGraphEntry* left)
{ {
SAL_WARN_IF( pos.nIndex < 0, "starmath", "nIndex shouldn't be -1!" ); assert(pos.nIndex >= 0);
auto entry = o3tl::make_unique<SmCaretPosGraphEntry>(pos, left, nullptr); auto entry = o3tl::make_unique<SmCaretPosGraphEntry>(pos, left, nullptr);
SmCaretPosGraphEntry* e = entry.get(); SmCaretPosGraphEntry* e = entry.get();
//Set Left and Right to point to the entry itself if they are NULL //Set Left and Right to point to the entry itself if they are NULL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment