commit f6282dfec7c7d53fd92d7270f8806a39a9c5d75b
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Sun Oct 20 20:50:23 2019 +0200

    Be careful before using buffer parameters in colAlign
    
    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.
    
    (cherry picked from commit 44816adce634c8a06c1ff0591adbcf042ec4c072)
---
 src/mathed/InsetMathGrid.cpp  |   12 +++++++-----
 src/mathed/InsetMathGrid.h    |    2 +-
 src/mathed/InsetMathHull.cpp  |    4 ++--
 src/mathed/InsetMathSplit.cpp |    4 ++--
 status.23x                    |    2 ++
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 2ae9d49..1560489 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1844,8 +1844,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:
@@ -1854,10 +1853,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:
diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h
index 2e48453..46a485d 100644
--- a/src/mathed/InsetMathGrid.h
+++ b/src/mathed/InsetMathGrid.h
@@ -271,7 +271,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);
 
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index f5fb039..d6d804d 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -446,7 +446,7 @@ bool InsetMathHull::idxLast(Cursor & cur) 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);
 }
 
 
@@ -468,7 +468,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;
        }
diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp
index 200a0bc..ebc8162 100644
--- a/src/mathed/InsetMathSplit.cpp
+++ b/src/mathed/InsetMathSplit.cpp
@@ -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);
 }
 
diff --git a/status.23x b/status.23x
index bb1fd59..ca88d66 100644
--- a/status.23x
+++ b/status.23x
@@ -152,6 +152,8 @@ What's new
 
 - Fix crash when inserting some macros (bug 11686).
 
+- Avoid future crashes with math split insets by adding an extra test.
+
 
 * INTERNALS
 
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to