never ask for one past last

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6479 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-03-13 10:30:28 +00:00
parent a44d452b15
commit a915be94cb
8 changed files with 115 additions and 58 deletions

View File

@ -1,20 +1,16 @@
src/BufferView.C
src/BufferView_pimpl.C
src/Chktex.C
src/CutAndPaste.C
src/LColor.C
src/LaTeX.C
src/LyXAction.C
src/MenuBackend.C
src/buffer.C src/buffer.C
src/bufferlist.C src/bufferlist.C
src/BufferView.C
src/bufferview_funcs.C src/bufferview_funcs.C
src/BufferView_pimpl.C
src/Chktex.C
src/converter.C src/converter.C
src/CutAndPaste.C
src/debug.C src/debug.C
src/exporter.C src/exporter.C
src/format.C src/format.C
src/frontends/LyXView.C src/frontends/controllers/biblio.C
src/frontends/controllers/ButtonController.h src/frontends/controllers/character.C
src/frontends/controllers/ControlAboutlyx.C src/frontends/controllers/ControlAboutlyx.C
src/frontends/controllers/ControlBibtex.C src/frontends/controllers/ControlBibtex.C
src/frontends/controllers/ControlCharacter.C src/frontends/controllers/ControlCharacter.C
@ -30,14 +26,14 @@ src/frontends/controllers/ControlSearch.C
src/frontends/controllers/ControlSpellchecker.C src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/ControlThesaurus.C src/frontends/controllers/ControlThesaurus.C
src/frontends/controllers/ControlVCLog.C src/frontends/controllers/ControlVCLog.C
src/frontends/controllers/biblio.C
src/frontends/controllers/character.C
src/frontends/controllers/frnt_lang.C src/frontends/controllers/frnt_lang.C
src/frontends/controllers/helper_funcs.C src/frontends/controllers/helper_funcs.C
src/frontends/gnome/GLog.C src/frontends/gnome/GLog.C
src/frontends/LyXView.C
src/frontends/qt2/Alert_pimpl.C src/frontends/qt2/Alert_pimpl.C
src/frontends/qt2/Dialogs3.C src/frontends/qt2/Dialogs3.C
src/frontends/qt2/FileDialog.C src/frontends/qt2/FileDialog.C
src/frontends/qt2/lengthcombo.C
src/frontends/qt2/QAbout.C src/frontends/qt2/QAbout.C
src/frontends/qt2/QBibitem.C src/frontends/qt2/QBibitem.C
src/frontends/qt2/QBibtex.C src/frontends/qt2/QBibtex.C
@ -50,16 +46,16 @@ src/frontends/qt2/QCommandBuffer.C
src/frontends/qt2/QDelimiterDialog.C src/frontends/qt2/QDelimiterDialog.C
src/frontends/qt2/QDocument.C src/frontends/qt2/QDocument.C
src/frontends/qt2/QDocumentDialog.C src/frontends/qt2/QDocumentDialog.C
src/frontends/qt2/QERT.C
src/frontends/qt2/QError.C src/frontends/qt2/QError.C
src/frontends/qt2/QERT.C
src/frontends/qt2/QExternal.C src/frontends/qt2/QExternal.C
src/frontends/qt2/QExternalDialog.C src/frontends/qt2/QExternalDialog.C
src/frontends/qt2/QFloat.C src/frontends/qt2/QFloat.C
src/frontends/qt2/QGraphics.C src/frontends/qt2/QGraphics.C
src/frontends/qt2/QGraphicsDialog.C src/frontends/qt2/QGraphicsDialog.C
src/frontends/qt2/QInclude.C src/frontends/qt2/QInclude.C
src/frontends/qt2/QLPrintDialog.C
src/frontends/qt2/QLog.C src/frontends/qt2/QLog.C
src/frontends/qt2/QLPrintDialog.C
src/frontends/qt2/QMathDialog.C src/frontends/qt2/QMathDialog.C
src/frontends/qt2/QMathMatrixDialog.C src/frontends/qt2/QMathMatrixDialog.C
src/frontends/qt2/QMinipage.C src/frontends/qt2/QMinipage.C
@ -72,18 +68,19 @@ src/frontends/qt2/QSearch.C
src/frontends/qt2/QSendto.C src/frontends/qt2/QSendto.C
src/frontends/qt2/QShowFile.C src/frontends/qt2/QShowFile.C
src/frontends/qt2/QSpellchecker.C src/frontends/qt2/QSpellchecker.C
src/frontends/qt2/Qt2BC.h
src/frontends/qt2/QTabular.C src/frontends/qt2/QTabular.C
src/frontends/qt2/QTabularCreate.C src/frontends/qt2/QTabularCreate.C
src/frontends/qt2/QTexinfo.C src/frontends/qt2/QTexinfo.C
src/frontends/qt2/QThesaurus.C src/frontends/qt2/QThesaurus.C
src/frontends/qt2/QToc.C src/frontends/qt2/QToc.C
src/frontends/qt2/QtView.C
src/frontends/qt2/QURL.C src/frontends/qt2/QURL.C
src/frontends/qt2/QVCLog.C src/frontends/qt2/QVCLog.C
src/frontends/qt2/QWrap.C src/frontends/qt2/QWrap.C
src/frontends/qt2/QtView.C
src/frontends/qt2/lengthcombo.C
src/frontends/xforms/Alert_pimpl.C src/frontends/xforms/Alert_pimpl.C
src/frontends/xforms/ColorHandler.C src/frontends/xforms/ColorHandler.C
src/frontends/xforms/combox.C
src/frontends/xforms/Dialogs3.C src/frontends/xforms/Dialogs3.C
src/frontends/xforms/FileDialog.C src/frontends/xforms/FileDialog.C
src/frontends/xforms/FormAboutlyx.C src/frontends/xforms/FormAboutlyx.C
@ -95,8 +92,8 @@ src/frontends/xforms/FormCharacter.C
src/frontends/xforms/FormCitation.C src/frontends/xforms/FormCitation.C
src/frontends/xforms/FormDialogView.C src/frontends/xforms/FormDialogView.C
src/frontends/xforms/FormDocument.C src/frontends/xforms/FormDocument.C
src/frontends/xforms/FormERT.C
src/frontends/xforms/FormError.C src/frontends/xforms/FormError.C
src/frontends/xforms/FormERT.C
src/frontends/xforms/FormExternal.C src/frontends/xforms/FormExternal.C
src/frontends/xforms/FormFiledialog.C src/frontends/xforms/FormFiledialog.C
src/frontends/xforms/FormFloat.C src/frontends/xforms/FormFloat.C
@ -128,15 +125,15 @@ src/frontends/xforms/FormToc.C
src/frontends/xforms/FormUrl.C src/frontends/xforms/FormUrl.C
src/frontends/xforms/FormVCLog.C src/frontends/xforms/FormVCLog.C
src/frontends/xforms/FormWrap.C src/frontends/xforms/FormWrap.C
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/XMiniBuffer.C
src/frontends/xforms/combox.C
src/frontends/xforms/input_validators.C src/frontends/xforms/input_validators.C
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/xformsBC.h
src/frontends/xforms/xforms_helpers.C src/frontends/xforms/xforms_helpers.C
src/frontends/xforms/XMiniBuffer.C
src/gettext.h src/gettext.h
src/importer.C src/importer.C
src/insets/inset.C
src/insets/insetbibtex.C src/insets/insetbibtex.C
src/insets/inset.C
src/insets/insetcaption.C src/insets/insetcaption.C
src/insets/inseterror.C src/insets/inseterror.C
src/insets/insetert.C src/insets/insetert.C
@ -163,12 +160,15 @@ src/insets/insetwrap.C
src/ispell.C src/ispell.C
src/kbsequence.C src/kbsequence.C
src/language.C src/language.C
src/LaTeX.C
src/LColor.C
src/lengthcommon.C src/lengthcommon.C
src/LyXAction.C
src/lyx_cb.C src/lyx_cb.C
src/lyx_main.C
src/lyxfind.C src/lyxfind.C
src/lyxfont.C src/lyxfont.C
src/lyxfunc.C src/lyxfunc.C
src/lyx_main.C
src/lyxrc.C src/lyxrc.C
src/lyxtextclasslist.C src/lyxtextclasslist.C
src/lyxvc.C src/lyxvc.C
@ -177,10 +177,12 @@ src/mathed/formulamacro.C
src/mathed/math_hullinset.C src/mathed/math_hullinset.C
src/mathed/math_parboxinset.C src/mathed/math_parboxinset.C
src/mathed/ref_inset.C src/mathed/ref_inset.C
src/MenuBackend.C
src/paragraph.C src/paragraph.C
src/paragraph_funcs.C
src/rowpainter.C src/rowpainter.C
src/support/filetools.C src/support/filetools.C
src/tabular.C src/tabular.C
src/text.C
src/text2.C src/text2.C
src/text3.C src/text3.C
src/text.C

View File

@ -1,3 +1,28 @@
2003-03-13 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C (setCursor): never ask for one past last
(setCursor): add some debugging messages.
* text.C (singleWidth): never ask for one past last
(singleWidth): ditto
(leftMargin): ditto
(rightMargin): ditto
(rowBreakPoint): ditto
(setHeightOfRow): ditto
(prepareToPrint): ditto
* rowpainter.C (paintBackground): never ask for one past last
(paintText): never ask for one past last
* paragraph_pimpl.C (getChar): make the assert stricter, never
allow the one past last pos to be taken
* paragraph.C (getChar): ws changes only
* lyxrow.C (nextRowIsAllInset): never ask for one past last
(numberOfSeparators): ditto
(numberOfHfills): ditto
2003-03-12 John Levon <levon@movementarian.org> 2003-03-12 John Levon <levon@movementarian.org>
* author.h: * author.h:

View File

@ -159,6 +159,9 @@ namespace {
bool nextRowIsAllInset(Row const & row, pos_type last) bool nextRowIsAllInset(Row const & row, pos_type last)
{ {
if (last + 1 >= row.par()->size())
return false;
if (!row.par()->isInset(last + 1)) if (!row.par()->isInset(last + 1))
return false; return false;
@ -192,7 +195,7 @@ int Row::numberOfSeparators() const
pos_type p = max(pos(), par()->beginningOfBody()); pos_type p = max(pos(), par()->beginningOfBody());
int n = 0; int n = 0;
for (; p <= last; ++p) { for (; p < last; ++p) {
if (par()->isSeparator(p)) { if (par()->isSeparator(p)) {
++n; ++n;
} }
@ -208,7 +211,7 @@ int Row::numberOfHfills() const
// hfill *DO* count at the beginning of paragraphs! // hfill *DO* count at the beginning of paragraphs!
if (first) { if (first) {
while (first <= last && par()->isHfill(first)) { while (first < last && par()->isHfill(first)) {
++first; ++first;
} }
} }
@ -218,7 +221,7 @@ int Row::numberOfHfills() const
int n = 0; int n = 0;
// last, because the end is ignored! // last, because the end is ignored!
for (pos_type p = first; p <= last; ++p) { for (pos_type p = first; p < last; ++p) {
if (par()->isHfill(p)) if (par()->isHfill(p))
++n; ++n;
} }

View File

@ -252,12 +252,14 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
{ {
// This is in the critical path for loading! //lyx::Assert(pos <= siz);
pos_type const siz = size();
lyx::Assert(pos <= siz);
// This is stronger, and I belive that this is the assertion // This is stronger, and I belive that this is the assertion
// that we should really use. (Lgb) // that we should really use. (Lgb)
//Assert(pos < size()); lyx::Assert(pos < size());
#if 0
// This is in the critical path for loading!
pos_type const siz = size();
// Then this has no meaning. (Lgb) // Then this has no meaning. (Lgb)
if (!siz || pos == siz) { if (!siz || pos == siz) {
@ -266,7 +268,7 @@ Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
<< " is a bit silly !" << endl; << " is a bit silly !" << endl;
return '\0'; return '\0';
} }
#endif
return text[pos]; return text[pos];
} }

View File

@ -312,6 +312,7 @@ bool RowPainter::paintBackground()
Inset const * inset = 0; Inset const * inset = 0;
if (!bv_.screen().forceClear() && last == row_.pos() if (!bv_.screen().forceClear() && last == row_.pos()
&& row_.pos() < par_.size()
&& par_.isInset(row_.pos())) { && par_.isInset(row_.pos())) {
inset = par_.getInset(row_.pos()); inset = par_.getInset(row_.pos());
clear_area = inset->doClearArea(); clear_area = inset->doClearArea();
@ -898,6 +899,11 @@ bool RowPainter::paintText()
break; break;
pos_type pos = text_.vis2log(vpos); pos_type pos = text_.vis2log(vpos);
if (pos >= par_.size()) {
++vpos;
continue;
}
if (x_ + singleWidth(pos) < 0) { if (x_ + singleWidth(pos) < 0) {
x_ += singleWidth(pos); x_ += singleWidth(pos);
++vpos; ++vpos;

View File

@ -206,6 +206,9 @@ unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
int LyXText::singleWidth(BufferView * bview, Paragraph * par, int LyXText::singleWidth(BufferView * bview, Paragraph * par,
pos_type pos) const pos_type pos) const
{ {
if (pos >= par->size())
return 0;
char const c = par->getChar(pos); char const c = par->getChar(pos);
return singleWidth(bview, par, pos, c); return singleWidth(bview, par, pos, c);
} }
@ -214,6 +217,9 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
int LyXText::singleWidth(BufferView * bview, Paragraph * par, int LyXText::singleWidth(BufferView * bview, Paragraph * par,
pos_type pos, char c) const pos_type pos, char c) const
{ {
if (pos >= par->size())
return 0;
LyXFont const font = getFont(bview->buffer(), par, pos); LyXFont const font = getFont(bview->buffer(), par, pos);
// The most common case is handled first (Asger) // The most common case is handled first (Asger)
@ -422,6 +428,8 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
int LyXText::leftMargin(BufferView * bview, Row const * row) const int LyXText::leftMargin(BufferView * bview, Row const * row) const
{ {
Inset * ins; Inset * ins;
if (row->pos() < row->par()->size())
if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) && if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
(ins = row->par()->getInset(row->pos())) && (ins = row->par()->getInset(row->pos())) &&
(ins->needFullRow() || ins->display())) (ins->needFullRow() || ins->display()))
@ -615,6 +623,8 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
int LyXText::rightMargin(Buffer const & buf, Row const & row) const int LyXText::rightMargin(Buffer const & buf, Row const & row) const
{ {
Inset * ins; Inset * ins;
if (row.pos() < row.par()->size())
if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) && if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
(ins=row.par()->getInset(row.pos())) && (ins=row.par()->getInset(row.pos())) &&
(ins->needFullRow() || ins->display())) (ins->needFullRow() || ins->display()))
@ -722,7 +732,9 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
pos_type const body_pos = par->beginningOfBody(); pos_type const body_pos = par->beginningOfBody();
pos_type const last = par->size(); pos_type const last = par->size();
pos_type point = last; pos_type point = last;
pos_type i = pos;
if (pos == last)
return last;
// Now we iterate through until we reach the right margin // Now we iterate through until we reach the right margin
// or the end of the par, then choose the possible break // or the end of the par, then choose the possible break
@ -734,7 +746,8 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
// pixel width since last breakpoint // pixel width since last breakpoint
int chunkwidth = 0; int chunkwidth = 0;
for (i = pos; i < last; ++i) { pos_type i = pos;
for (; i < last; ++i) {
if (par->isNewline(i)) { if (par->isNewline(i)) {
point = i; point = i;
@ -976,7 +989,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
int maxwidth = 0; int maxwidth = 0;
// Check if any insets are larger // Check if any insets are larger
for (pos_type pos = row->pos(); pos <= pos_end; ++pos) { for (pos_type pos = row->pos(); pos < pos_end; ++pos) {
if (row->par()->isInset(pos)) { if (row->par()->isInset(pos)) {
tmpfont = getFont(bview->buffer(), row->par(), pos); tmpfont = getFont(bview->buffer(), row->par(), pos);
tmpinset = row->par()->getInset(pos); tmpinset = row->par()->getInset(pos);
@ -1594,7 +1607,8 @@ void LyXText::insertChar(BufferView * bview, char c)
} }
// the display inset stuff // the display inset stuff
if (cursor.row()->par()->isInset(cursor.row()->pos())) { if (cursor.row()->pos() < cursor.row()->par()->size()
&& cursor.row()->par()->isInset(cursor.row()->pos())) {
Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos()); Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
if (inset && (inset->display() || inset->needFullRow())) { if (inset && (inset->display() || inset->needFullRow())) {
// force a new break // force a new break
@ -1814,7 +1828,8 @@ void LyXText::prepareToPrint(BufferView * bview,
// center displayed insets // center displayed insets
Inset * inset; Inset * inset;
if (row->par()->isInset(row->pos()) if (row->pos() < row->par()->size()
&& row->par()->isInset(row->pos())
&& (inset = row->par()->getInset(row->pos())) && (inset = row->par()->getInset(row->pos()))
&& (inset->display())) // || (inset->scroll() < 0))) && (inset->display())) // || (inset->scroll() < 0)))
align = (inset->lyxCode() == Inset::MATHMACRO_CODE) align = (inset->lyxCode() == Inset::MATHMACRO_CODE)

View File

@ -1769,6 +1769,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
Inset * ins; Inset * ins;
if (row->previous() && pos && if (row->previous() && pos &&
row->previous()->par() == row->par() && row->previous()->par() == row->par() &&
pos < par->size() &&
par->getChar(pos) == Paragraph::META_INSET && par->getChar(pos) == Paragraph::META_INSET &&
(ins = par->getInset(pos)) && (ins->needFullRow() || ins->display())) (ins = par->getInset(pos)) && (ins->needFullRow() || ins->display()))
{ {
@ -1786,13 +1787,16 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
// None of these should happen, but we're scaredy-cats // None of these should happen, but we're scaredy-cats
if (pos > par->size()) { if (pos > par->size()) {
lyxerr << "dont like 1 please report" << endl;
pos = 0; pos = 0;
cur.pos(0); cur.pos(0);
} else if (pos > last + 1) { } else if (pos > last + 1) {
lyxerr << "dont like 2 please report" << endl;
// This shouldn't happen. // This shouldn't happen.
pos = last + 1; pos = last + 1;
cur.pos(pos); cur.pos(pos);
} else if (pos < row->pos()) { } else if (pos < row->pos()) {
lyxerr << "dont like 3 please report" << endl;
pos = row->pos(); pos = row->pos();
cur.pos(pos); cur.pos(pos);
} }