]> git.lyx.org Git - features.git/commitdiff
* fix crash due to a missing test whether thisSlice is -1 or a valid slice number
authorStefan Schimanski <sts@lyx.org>
Mon, 12 Nov 2007 22:12:39 +0000 (22:12 +0000)
committerStefan Schimanski <sts@lyx.org>
Mon, 12 Nov 2007 22:12:39 +0000 (22:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21556 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/MathData.cpp

index d9d42c34ae39b21be0390ca4300af4a0a8ebf4c9..8bba8909e93f883c014f39700c9eceb87442cbe5 100644 (file)
@@ -564,20 +564,23 @@ void MathData::attachMacroParameters(Cursor & cur,
        
        // remove them from the MathData
        erase(begin() + macroPos + 1, begin() + p);
+
+       // fix up cursor
+       if (thisSlice != -1) {
+               // fix cursor if right of p
+               if (thisPos >= int(p))
+                       cur[thisSlice].pos() -= p - (macroPos + 1);
        
-       // fix cursor if right of p
-       if (thisPos >= int(p))
-               cur[thisSlice].pos() -= p - (macroPos + 1);
-       
-       // was the macro inset just inserted and was now folded?
-       if (cur[thisSlice].pos() == int(macroPos + 1)
-                       && fromInitToNormalMode
-                       && macroInset->arity() > 0
-                       && thisSlice + 1 == int(cur.depth())) {
-               // then enter it if the cursor was just behind
-               cur[thisSlice].pos() = macroPos;
-               cur.push_back(CursorSlice(*macroInset));
-               macroInset->idxFirst(cur);
+               // was the macro inset just inserted and was now folded?
+               if (cur[thisSlice].pos() == int(macroPos + 1)
+                               && fromInitToNormalMode
+                               && macroInset->arity() > 0
+                               && thisSlice + 1 == int(cur.depth())) {
+                       // then enter it if the cursor was just behind
+                       cur[thisSlice].pos() = macroPos;
+                       cur.push_back(CursorSlice(*macroInset));
+                       macroInset->idxFirst(cur);
+               }
        }
 }
 
@@ -618,7 +621,8 @@ void MathData::collectOptionalParameters(Cursor & cur,
                        params.push_back(optarg);
                
                // place cursor in optional argument of macro
-               if (thisPos >= int(pos) && thisPos <= int(right)) {
+               if (thisSlice != -1
+                               && thisPos >= int(pos) && thisPos <= int(right)) {
                        int paramPos = std::max(0, thisPos - int(pos) - 1);
                        std::vector<CursorSlice> x;
                        cur.cutOff(thisSlice, x);
@@ -652,7 +656,7 @@ void MathData::collectParameters(Cursor & cur,
                // fix cursor
                std::vector<CursorSlice> argSlices;
                int argPos = 0;
-               if (thisPos == int(pos)) {
+               if (thisSlice != -1 && thisPos == int(pos)) {
                        cur.cutOff(thisSlice, argSlices);
                }
                
@@ -693,7 +697,7 @@ void MathData::collectParameters(Cursor & cur,
                }
                
                // put cursor in argument again
-               if (thisPos == int(pos)) {
+               if (thisSlice != - 1 && thisPos == int(pos)) {
                        cur.append(params.size() - 1, argPos);
                        cur.append(argSlices);
                        cur[thisSlice].pos() = macroPos;