]> git.lyx.org Git - features.git/commitdiff
Ensure that the accessor index is valid.
authorAngus Leeming <leeming@lyx.org>
Mon, 5 Apr 2004 10:37:16 +0000 (10:37 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 5 Apr 2004 10:37:16 +0000 (10:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8599 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_scriptinset.C

index c9e12d0b0ab9827fe094fe7701babb912e05b17d..b8a2c642a0eb9f6323b1841c949be6c01ccfedc3 100644 (file)
@@ -1,3 +1,8 @@
+2004-05-04  Angus Leeming  <leeming@lyx.org>
+
+       * math_scriptinset.C (up, down, notifyCursorLeaves): ensure that
+       accessor index is valid.
+
 2004-05-04  Angus Leeming  <leeming@lyx.org>
 
        * formulamacro.C:
index a2c397ad537f7cbaf958d1d943490309313ed166..eddc7feb2583279d8546de85324ac4b4a0e105ea 100644 (file)
@@ -42,6 +42,7 @@ MathScriptInset::MathScriptInset(bool up)
 MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
        : MathNestInset(2), cell_1_is_up_(up), limits_(0)
 {
+       BOOST_ASSERT(nargs() >= 1);
        cell(0).push_back(at);
 }
 
@@ -83,24 +84,40 @@ bool MathScriptInset::idxLast(LCursor & cur) const
 
 MathArray const & MathScriptInset::down() const
 {
-       return nargs() == 2 ? cell(2) : cell(1);
+#if 1
+       if (nargs() == 3)
+               return cell(2);
+       BOOST_ASSERT(nargs() > 1);
+       return cell(1);
+#else
+       return nargs() == 3 ? cell(2) : cell(1);
+#endif
 }
 
 
 MathArray & MathScriptInset::down()
 {
-       return nargs() == 2 ? cell(2) : cell(1);
+#if 1
+       if (nargs() == 3)
+               return cell(2);
+       BOOST_ASSERT(nargs() > 1);
+       return cell(1);
+#else
+       return nargs() == 3 ? cell(2) : cell(1);
+#endif
 }
 
 
 MathArray const & MathScriptInset::up() const
 {
+       BOOST_ASSERT(nargs() > 1);
        return cell(1);
 }
 
 
 MathArray & MathScriptInset::up()
 {
+       BOOST_ASSERT(nargs() > 1);
        return cell(1);
 }
 
@@ -544,9 +561,9 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx)
        MathNestInset::notifyCursorLeaves(idx);
 
        // remove empty scripts if possible
-       if (idx == 2 && cell(2).empty()) {
+       if (idx == 2 && nargs() > 2 && cell(2).empty()) {
                removeScript(false); // must be a subscript...
-       } else if (idx == 1 && cell(1).empty()) {
+       } else if (idx == 1 && nargs() > 1 && cell(1).empty()) {
                if (nargs() == 2) {
                        cell_1_is_up_ = false;
                        cell(1) = cell(2);