]> git.lyx.org Git - features.git/commitdiff
Be careful before using buffer parameters in colAlign
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 20 Oct 2019 18:50:23 +0000 (20:50 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 21 Oct 2019 15:02:39 +0000 (17:02 +0200)
Make InsetGrid::colAlign a normal method and make it check whether
buffer is valid before using it. This avoids crashes as we have seen
in 2.3.3 (see e.g. #11686).

There is still an assertion so that failure is noticeable before release.

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathSplit.cpp

index 910450d378643290046df936192080fb7ca9d270..34fb53dcee471524809aae86064afcde71600ba8 100644 (file)
@@ -1831,8 +1831,7 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-// static
-char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & bp)
+char InsetMathGrid::colAlign(HullType type, col_type col) const
 {
        switch (type) {
        case hullEqnArray:
@@ -1841,10 +1840,13 @@ char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & b
        case hullMultline:
                return 'c';
        case hullGather:
-               if (!bp.is_math_indent)
-                       return 'c';
-               else
+               LASSERT(isBufferValid(),
+                               LYXERR0("Buffer not set correctly. Please report!");
+                               return 'c';);
+               if (buffer().params().is_math_indent)
                        return 'l';
+               else
+                       return 'c';
 
        case hullAlign:
        case hullAlignAt:
index b6d8044057df932754a0c9951971dc82c745398c..425a98a324640a73bbc87e03add4ea7517dff619 100644 (file)
@@ -272,7 +272,7 @@ protected:
        // InsetMathSplit.
        /// The value of a fixed col align for a certain hull type (can
        /// depend on the "indent math" setting).
-       static char colAlign(HullType type, col_type col,  BufferParams const &);
+       char colAlign(HullType type, col_type col) const;
        /// The value of a fixed col spacing for a certain hull type
        static int colSpace(HullType type, col_type col);
 
index 261f7f27bbff48fc799110883646483f0b6923f1..7da33199c6743541a33a902a7e0376b5ff840e6e 100644 (file)
@@ -430,7 +430,7 @@ InsetMath::mode_type InsetMathHull::currentMode() const
 // alignment is not implemented in the LyXHTML output.
 char InsetMathHull::defaultColAlign(col_type col)
 {
-       return colAlign(type_, col, buffer().params());
+       return colAlign(type_, col);
 }
 
 
@@ -452,7 +452,7 @@ char InsetMathHull::displayColAlign(idx_type idx) const
        case hullXAlignAt:
        case hullXXAlignAt:
        case hullFlAlign:
-               return colAlign(type_, col(idx), buffer().params());
+               return colAlign(type_, col(idx));
        default:
                break;
        }
index 200a0bc3c9fd3a23e0a6f7efe5142dd8af65385e..ebc8162dd91a38d4eeea15641b5879fc2b05d6e5 100644 (file)
@@ -62,7 +62,7 @@ char InsetMathSplit::defaultColAlign(col_type col)
            || name_ == "aligned"
            || name_ == "align"
            || name_ == "alignedat")
-               return colAlign(hullAlign, col, buffer().params());
+               return colAlign(hullAlign, col);
        return 'l';
 }
 
@@ -79,7 +79,7 @@ char InsetMathSplit::displayColAlign(idx_type idx) const
            || name_ == "aligned"
            || name_ == "align"
            || name_ == "alignedat")
-               return colAlign(hullAlign, col(idx), buffer().params());
+               return colAlign(hullAlign, col(idx));
        return InsetMathGrid::displayColAlign(idx);
 }