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.
This commit is contained in:
Jean-Marc Lasgouttes 2019-10-20 20:50:23 +02:00
parent 273d257f2a
commit 44816adce6
4 changed files with 12 additions and 10 deletions

View File

@ -1831,8 +1831,7 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
// static char InsetMathGrid::colAlign(HullType type, col_type col) const
char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & bp)
{ {
switch (type) { switch (type) {
case hullEqnArray: case hullEqnArray:
@ -1841,10 +1840,13 @@ char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & b
case hullMultline: case hullMultline:
return 'c'; return 'c';
case hullGather: case hullGather:
if (!bp.is_math_indent) LASSERT(isBufferValid(),
return 'c'; LYXERR0("Buffer not set correctly. Please report!");
else return 'c';);
if (buffer().params().is_math_indent)
return 'l'; return 'l';
else
return 'c';
case hullAlign: case hullAlign:
case hullAlignAt: case hullAlignAt:

View File

@ -272,7 +272,7 @@ protected:
// InsetMathSplit. // InsetMathSplit.
/// The value of a fixed col align for a certain hull type (can /// The value of a fixed col align for a certain hull type (can
/// depend on the "indent math" setting). /// 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 /// The value of a fixed col spacing for a certain hull type
static int colSpace(HullType type, col_type col); static int colSpace(HullType type, col_type col);

View File

@ -430,7 +430,7 @@ InsetMath::mode_type InsetMathHull::currentMode() const
// alignment is not implemented in the LyXHTML output. // alignment is not implemented in the LyXHTML output.
char InsetMathHull::defaultColAlign(col_type col) 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 hullXAlignAt:
case hullXXAlignAt: case hullXXAlignAt:
case hullFlAlign: case hullFlAlign:
return colAlign(type_, col(idx), buffer().params()); return colAlign(type_, col(idx));
default: default:
break; break;
} }

View File

@ -62,7 +62,7 @@ char InsetMathSplit::defaultColAlign(col_type col)
|| name_ == "aligned" || name_ == "aligned"
|| name_ == "align" || name_ == "align"
|| name_ == "alignedat") || name_ == "alignedat")
return colAlign(hullAlign, col, buffer().params()); return colAlign(hullAlign, col);
return 'l'; return 'l';
} }
@ -79,7 +79,7 @@ char InsetMathSplit::displayColAlign(idx_type idx) const
|| name_ == "aligned" || name_ == "aligned"
|| name_ == "align" || name_ == "align"
|| name_ == "alignedat") || name_ == "alignedat")
return colAlign(hullAlign, col(idx), buffer().params()); return colAlign(hullAlign, col(idx));
return InsetMathGrid::displayColAlign(idx); return InsetMathGrid::displayColAlign(idx);
} }