fix bug 1542 (crash wehn reading invalid equations)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9408 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2004-12-28 15:43:29 +00:00
parent 6145e436c6
commit 54a21aa305
2 changed files with 85 additions and 23 deletions

View File

@ -1,3 +1,9 @@
2004-12-22 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* math_parser.C (addRow, addCol): new, try to add a row or column to
a MathGridInset
* math_parser.C (parse1): use addRow and addCol, fixes bug 1542
2004-12-14 Angus Leeming <leeming@lyx.org>
* Makefile.am (AM_CPPFLAGS): Remove trailing slash from -Ifoo/

View File

@ -102,6 +102,65 @@ bool stared(string const & s)
}
/*!
* Add the row \p cellrow to \p grid.
* \returns wether the row could be added. Adding a row can fail for
* environments like "equation" that have a fixed number of rows.
*/
bool addRow(MathGridInset & grid, MathGridInset::row_type & cellrow,
string const & vskip)
{
++cellrow;
if (cellrow == grid.nrows()) {
//lyxerr << "adding row " << cellrow << endl;
grid.addRow(cellrow - 1);
if (cellrow == grid.nrows()) {
// We can't add a row to this grid, so let's
// append the content of this cell to the previous
// one.
// This does not happen in well formed .lyx files,
// but LyX versions 1.3.x and older could create
// such files and tex2lyx can still do that.
--cellrow;
lyxerr << "ignoring extra row";
if (!vskip.empty())
lyxerr << " with extra space " << vskip;
lyxerr << '.' << endl;
return false;
}
}
grid.vcrskip(LyXLength(vskip), cellrow - 1);
return true;
}
/*!
* Add the column \p cellcol to \p grid.
* \returns wether the column could be added. Adding a column can fail for
* environments like "eqnarray" that have a fixed number of columns.
*/
bool addCol(MathGridInset & grid, MathGridInset::col_type & cellcol)
{
++cellcol;
if (cellcol == grid.ncols()) {
//lyxerr << "adding column " << cellcol << endl;
grid.addCol(cellcol - 1);
if (cellcol == grid.ncols()) {
// We can't add a column to this grid, so let's
// append the content of this cell to the previous
// one.
// This does not happen in well formed .lyx files,
// but LyX versions 1.3.x and older could create
// such files and tex2lyx can still do that.
--cellcol;
lyxerr << "ignoring extra column." << endl;
return false;
}
}
return true;
}
// These are TeX's catcodes
enum CatCode {
catEscape, // 0 backslash
@ -696,13 +755,11 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
}
else if (t.cat() == catAlign) {
++cellcol;
//lyxerr << " column now " << cellcol << " max: " << grid.ncols() << endl;
if (cellcol == grid.ncols()) {
//lyxerr << "adding column " << cellcol << endl;
grid.addCol(cellcol - 1);
}
cell = &grid.cell(grid.index(cellrow, cellcol));
//lyxerr << " column now " << (cellcol + 1)
// << " max: " << grid.ncols() << endl;
if (addCol(grid, cellcol))
cell = &grid.cell(grid.index(cellrow,
cellcol));
}
else if (t.cat() == catSuper || t.cat() == catSub) {
@ -860,14 +917,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
}
else if (t.cs() == "\\") {
grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
++cellrow;
cellcol = 0;
if (cellrow == grid.nrows())
grid.addRow(cellrow - 1);
if (grid.asHullInset())
grid.asHullInset()->numbered(cellrow, numbered);
cell = &grid.cell(grid.index(cellrow, cellcol));
if (addRow(grid, cellrow, getArg('[', ']'))) {
cellcol = 0;
if (grid.asHullInset())
grid.asHullInset()->numbered(
cellrow, numbered);
cell = &grid.cell(grid.index(cellrow,
cellcol));
}
}
#if 0
@ -881,16 +938,15 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
}
// resize the table if necessary
for (int i = 0; i < cols; ++i) {
++cellcol;
if (cellcol == grid.ncols()) {
//lyxerr << "adding column " << cellcol << endl;
grid.addCol(cellcol - 1);
if (addCol(grid, cellcol)) {
cell = &grid.cell(grid.index(
cellrow, cellcol));
// mark this as dummy
grid.cellinfo(grid.index(
cellrow, cellcol)).dummy_ = true;
}
cell = &grid.cell(grid.index(cellrow, cellcol));
// mark this as dummy
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
}
// the last cell is the real thng, not a dummy
// the last cell is the real thing, not a dummy
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
// read special alignment