]> git.lyx.org Git - lyx.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>
Tue, 22 Oct 2019 16:10:00 +0000 (18:10 +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.

(cherry picked from commit 44816adce634c8a06c1ff0591adbcf042ec4c072)

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathSplit.cpp
status.23x

index 2ae9d494db3bc3c6b9f7f78e1261adb4a3fbdc5a..156048947cd8393cc0ebf8795320b6cae53d498f 100644 (file)
@@ -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:
index 2e48453601a02d557863d46c1dbf551e78584464..46a485d086904830382560faf4dc5fb7284e7d43 100644 (file)
@@ -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);
 
index f5fb039a69e8e69200ebe4267eb3e2364cd8893a..d6d804dd8c8db02ade3927a0682a1e6f2aa47645 100644 (file)
@@ -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;
        }
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);
 }
 
index bb1fd59f081e089328b47c3edfccfe22d8ce5bfc..ca88d6686ce9f4489a1028aaed9773a6ead707f8 100644 (file)
@@ -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