From 4420370ee0b6640783f53f66cc1a3dba60c345e3 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 5 Apr 2004 10:37:16 +0000 Subject: [PATCH] Ensure that the accessor index is valid. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8599 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 5 +++++ src/mathed/math_scriptinset.C | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index c9e12d0b0a..b8a2c642a0 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ +2004-05-04 Angus Leeming + + * math_scriptinset.C (up, down, notifyCursorLeaves): ensure that + accessor index is valid. + 2004-05-04 Angus Leeming * formulamacro.C: diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index a2c397ad53..eddc7feb25 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -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); -- 2.39.5