From a915be94cb0ce4474d4126e2a87a97ebb692f5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 13 Mar 2003 10:30:28 +0000 Subject: [PATCH] never ask for one past last git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6479 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 48 +++++++++++++++++++------------------ src/ChangeLog | 25 ++++++++++++++++++++ src/lyxrow.C | 9 ++++--- src/paragraph.C | 6 ++--- src/paragraph_pimpl.C | 12 ++++++---- src/rowpainter.C | 8 ++++++- src/text.C | 55 +++++++++++++++++++++++++++---------------- src/text2.C | 10 +++++--- 8 files changed, 115 insertions(+), 58 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 4a5d31c732..701bbdf17c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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/bufferlist.C +src/BufferView.C src/bufferview_funcs.C +src/BufferView_pimpl.C +src/Chktex.C src/converter.C +src/CutAndPaste.C src/debug.C src/exporter.C src/format.C -src/frontends/LyXView.C -src/frontends/controllers/ButtonController.h +src/frontends/controllers/biblio.C +src/frontends/controllers/character.C src/frontends/controllers/ControlAboutlyx.C src/frontends/controllers/ControlBibtex.C src/frontends/controllers/ControlCharacter.C @@ -30,14 +26,14 @@ src/frontends/controllers/ControlSearch.C src/frontends/controllers/ControlSpellchecker.C src/frontends/controllers/ControlThesaurus.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/helper_funcs.C src/frontends/gnome/GLog.C +src/frontends/LyXView.C src/frontends/qt2/Alert_pimpl.C src/frontends/qt2/Dialogs3.C src/frontends/qt2/FileDialog.C +src/frontends/qt2/lengthcombo.C src/frontends/qt2/QAbout.C src/frontends/qt2/QBibitem.C src/frontends/qt2/QBibtex.C @@ -50,16 +46,16 @@ src/frontends/qt2/QCommandBuffer.C src/frontends/qt2/QDelimiterDialog.C src/frontends/qt2/QDocument.C src/frontends/qt2/QDocumentDialog.C -src/frontends/qt2/QERT.C src/frontends/qt2/QError.C +src/frontends/qt2/QERT.C src/frontends/qt2/QExternal.C src/frontends/qt2/QExternalDialog.C src/frontends/qt2/QFloat.C src/frontends/qt2/QGraphics.C src/frontends/qt2/QGraphicsDialog.C src/frontends/qt2/QInclude.C -src/frontends/qt2/QLPrintDialog.C src/frontends/qt2/QLog.C +src/frontends/qt2/QLPrintDialog.C src/frontends/qt2/QMathDialog.C src/frontends/qt2/QMathMatrixDialog.C src/frontends/qt2/QMinipage.C @@ -72,18 +68,19 @@ src/frontends/qt2/QSearch.C src/frontends/qt2/QSendto.C src/frontends/qt2/QShowFile.C src/frontends/qt2/QSpellchecker.C +src/frontends/qt2/Qt2BC.h src/frontends/qt2/QTabular.C src/frontends/qt2/QTabularCreate.C src/frontends/qt2/QTexinfo.C src/frontends/qt2/QThesaurus.C src/frontends/qt2/QToc.C +src/frontends/qt2/QtView.C src/frontends/qt2/QURL.C src/frontends/qt2/QVCLog.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/ColorHandler.C +src/frontends/xforms/combox.C src/frontends/xforms/Dialogs3.C src/frontends/xforms/FileDialog.C src/frontends/xforms/FormAboutlyx.C @@ -95,8 +92,8 @@ src/frontends/xforms/FormCharacter.C src/frontends/xforms/FormCitation.C src/frontends/xforms/FormDialogView.C src/frontends/xforms/FormDocument.C -src/frontends/xforms/FormERT.C src/frontends/xforms/FormError.C +src/frontends/xforms/FormERT.C src/frontends/xforms/FormExternal.C src/frontends/xforms/FormFiledialog.C src/frontends/xforms/FormFloat.C @@ -128,15 +125,15 @@ src/frontends/xforms/FormToc.C src/frontends/xforms/FormUrl.C src/frontends/xforms/FormVCLog.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/Menubar_pimpl.C +src/frontends/xforms/xformsBC.h src/frontends/xforms/xforms_helpers.C +src/frontends/xforms/XMiniBuffer.C src/gettext.h src/importer.C -src/insets/inset.C src/insets/insetbibtex.C +src/insets/inset.C src/insets/insetcaption.C src/insets/inseterror.C src/insets/insetert.C @@ -163,12 +160,15 @@ src/insets/insetwrap.C src/ispell.C src/kbsequence.C src/language.C +src/LaTeX.C +src/LColor.C src/lengthcommon.C +src/LyXAction.C src/lyx_cb.C -src/lyx_main.C src/lyxfind.C src/lyxfont.C src/lyxfunc.C +src/lyx_main.C src/lyxrc.C src/lyxtextclasslist.C src/lyxvc.C @@ -177,10 +177,12 @@ src/mathed/formulamacro.C src/mathed/math_hullinset.C src/mathed/math_parboxinset.C src/mathed/ref_inset.C +src/MenuBackend.C src/paragraph.C +src/paragraph_funcs.C src/rowpainter.C src/support/filetools.C src/tabular.C -src/text.C src/text2.C src/text3.C +src/text.C diff --git a/src/ChangeLog b/src/ChangeLog index 3b5eb6a648..b711da17e5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,28 @@ +2003-03-13 Lars Gullik Bjønnes + + * 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 * author.h: diff --git a/src/lyxrow.C b/src/lyxrow.C index af4c7304fc..b12b17ad0f 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -159,6 +159,9 @@ namespace { bool nextRowIsAllInset(Row const & row, pos_type last) { + if (last + 1 >= row.par()->size()) + return false; + if (!row.par()->isInset(last + 1)) return false; @@ -192,7 +195,7 @@ int Row::numberOfSeparators() const pos_type p = max(pos(), par()->beginningOfBody()); int n = 0; - for (; p <= last; ++p) { + for (; p < last; ++p) { if (par()->isSeparator(p)) { ++n; } @@ -208,7 +211,7 @@ int Row::numberOfHfills() const // hfill *DO* count at the beginning of paragraphs! if (first) { - while (first <= last && par()->isHfill(first)) { + while (first < last && par()->isHfill(first)) { ++first; } } @@ -218,7 +221,7 @@ int Row::numberOfHfills() const int n = 0; // 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)) ++n; } diff --git a/src/paragraph.C b/src/paragraph.C index 53b9601704..b83a8a77a5 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -788,7 +788,7 @@ int Paragraph::beginningOfBody() const char previous_char = 0; char temp = 0; if (i < size()) { - previous_char = getChar(i); + previous_char = getChar(i); if (!isNewline(i)) { ++i; while (i < size() && previous_char != ' ') { @@ -1345,7 +1345,7 @@ string const Paragraph::asString(Buffer const * buffer, value_type const c = getUChar(buffer->params, i); if (IsPrintable(c)) os << c; - else if (c == META_INSET) + else if (c == META_INSET) getInset(i)->ascii(buffer, os); } @@ -1358,7 +1358,7 @@ void Paragraph::setInsetOwner(Inset * i) pimpl_->inset_owner = i; InsetList::iterator it = insetlist.begin(); InsetList::iterator end = insetlist.end(); - for (; it != end; ++it) + for (; it != end; ++it) if (it.getInset()) it.getInset()->setOwner(i); } diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index fd47d46e8a..63c72b8130 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -252,12 +252,14 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end) Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const { - // This is in the critical path for loading! - pos_type const siz = size(); - lyx::Assert(pos <= siz); + //lyx::Assert(pos <= siz); // This is stronger, and I belive that this is the assertion // 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) if (!siz || pos == siz) { @@ -266,7 +268,7 @@ Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const << " is a bit silly !" << endl; return '\0'; } - +#endif return text[pos]; } diff --git a/src/rowpainter.C b/src/rowpainter.C index 0f37a206d5..99e4b04b24 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -312,7 +312,8 @@ bool RowPainter::paintBackground() Inset const * inset = 0; if (!bv_.screen().forceClear() && last == row_.pos() - && par_.isInset(row_.pos())) { + && row_.pos() < par_.size() + && par_.isInset(row_.pos())) { inset = par_.getInset(row_.pos()); clear_area = inset->doClearArea(); } @@ -898,6 +899,11 @@ bool RowPainter::paintText() break; pos_type pos = text_.vis2log(vpos); + if (pos >= par_.size()) { + ++vpos; + continue; + } + if (x_ + singleWidth(pos) < 0) { x_ += singleWidth(pos); ++vpos; diff --git a/src/text.C b/src/text.C index 8110f198af..9769d34b02 100644 --- a/src/text.C +++ b/src/text.C @@ -62,7 +62,7 @@ int LyXText::top_y() const { if (!top_row_) return 0; - + int y = 0; for (Row * row = firstrow; row && row != top_row_; row = row->next()) { y += row->height(); @@ -76,7 +76,7 @@ void LyXText::top_y(int newy) if (!firstrow) return; lyxerr[Debug::GUI] << "setting top y = " << newy << endl; - + int y = newy; top_row_ = getRowNearY(y); top_row_offset_ = newy - y; @@ -206,6 +206,9 @@ unsigned char LyXText::transformChar(unsigned char c, Paragraph * par, int LyXText::singleWidth(BufferView * bview, Paragraph * par, pos_type pos) const { + if (pos >= par->size()) + return 0; + char const c = par->getChar(pos); return singleWidth(bview, par, pos, c); } @@ -214,6 +217,9 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par, int LyXText::singleWidth(BufferView * bview, Paragraph * par, pos_type pos, char c) const { + if (pos >= par->size()) + return 0; + LyXFont const font = getFont(bview->buffer(), par, pos); // The most common case is handled first (Asger) @@ -422,10 +428,12 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par, int LyXText::leftMargin(BufferView * bview, Row const * row) const { Inset * ins; - if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) && - (ins=row->par()->getInset(row->pos())) && - (ins->needFullRow() || ins->display())) - return LEFT_MARGIN; + + if (row->pos() < row->par()->size()) + if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) && + (ins = row->par()->getInset(row->pos())) && + (ins->needFullRow() || ins->display())) + return LEFT_MARGIN; LyXTextClass const & tclass = bview->buffer()->params.getLyXTextClass(); @@ -615,10 +623,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const int LyXText::rightMargin(Buffer const & buf, Row const & row) const { Inset * ins; - if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) && - (ins=row.par()->getInset(row.pos())) && - (ins->needFullRow() || ins->display())) - return PAPER_MARGIN; + + if (row.pos() < row.par()->size()) + if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) && + (ins=row.par()->getInset(row.pos())) && + (ins->needFullRow() || ins->display())) + return PAPER_MARGIN; LyXTextClass const & tclass = buf.params.getLyXTextClass(); LyXLayout_ptr const & layout = row.par()->layout(); @@ -722,7 +732,9 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const pos_type const body_pos = par->beginningOfBody(); pos_type const last = par->size(); pos_type point = last; - pos_type i = pos; + + if (pos == last) + return last; // Now we iterate through until we reach the right margin // 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 int chunkwidth = 0; - for (i = pos; i < last; ++i) { + pos_type i = pos; + for (; i < last; ++i) { if (par->isNewline(i)) { point = i; @@ -795,7 +808,7 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const if (!display) continue; - + // full row insets start at a new row if (i == pos) { if (pos < last - 1) { @@ -976,7 +989,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const int maxwidth = 0; // 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)) { tmpfont = getFont(bview->buffer(), row->par(), pos); tmpinset = row->par()->getInset(pos); @@ -1592,9 +1605,10 @@ void LyXText::insertChar(BufferView * bview, char c) return; } } - + // 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()); if (inset && (inset->display() || inset->needFullRow())) { // force a new break @@ -1787,7 +1801,7 @@ void LyXText::prepareToPrint(BufferView * bview, // is empty. if (!row->par()->empty()) ++nlh; - + if (nlh && !row->par()->getLabelWidthString().empty()) { fill_label_hfill = labelFill(*bview, *row) / nlh; } @@ -1814,8 +1828,9 @@ void LyXText::prepareToPrint(BufferView * bview, // center displayed insets Inset * inset; - if (row->par()->isInset(row->pos()) - && (inset=row->par()->getInset(row->pos())) + if (row->pos() < row->par()->size() + && row->par()->isInset(row->pos()) + && (inset = row->par()->getInset(row->pos())) && (inset->display())) // || (inset->scroll() < 0))) align = (inset->lyxCode() == Inset::MATHMACRO_CODE) ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER; @@ -1991,7 +2006,7 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to, // Move cursor to the beginning, when not already there. if (from.pos() && !from.par()->isSeparator(from.pos() - 1) && !(from.par()->isKomma(from.pos() - 1) - || from.par()->isNewline(from.pos() - 1))) + || from.par()->isNewline(from.pos() - 1))) cursorLeftOneWord(from); break; case PREVIOUS_WORD: diff --git a/src/text2.C b/src/text2.C index baf28126b0..10fc7e03d7 100644 --- a/src/text2.C +++ b/src/text2.C @@ -52,7 +52,7 @@ using lyx::pos_type; LyXText::LyXText(BufferView * bv) - : height(0), width(0), top_row_(0), top_row_offset_(0), + : height(0), width(0), top_row_(0), top_row_offset_(0), inset_owner(0), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), bv_owner(bv), status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) @@ -60,7 +60,7 @@ LyXText::LyXText(BufferView * bv) LyXText::LyXText(InsetText * inset) - : height(0), width(0), top_row_(0), top_row_offset_(0), + : height(0), width(0), top_row_(0), top_row_offset_(0), inset_owner(inset), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), bv_owner(0), status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) @@ -1769,8 +1769,9 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par, Inset * ins; if (row->previous() && pos && row->previous()->par() == row->par() && + pos < par->size() && par->getChar(pos) == Paragraph::META_INSET && - (ins=par->getInset(pos)) && (ins->needFullRow() || ins->display())) + (ins = par->getInset(pos)) && (ins->needFullRow() || ins->display())) { row = row->previous(); y -= row->height(); @@ -1786,13 +1787,16 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par, // None of these should happen, but we're scaredy-cats if (pos > par->size()) { + lyxerr << "dont like 1 please report" << endl; pos = 0; cur.pos(0); } else if (pos > last + 1) { + lyxerr << "dont like 2 please report" << endl; // This shouldn't happen. pos = last + 1; cur.pos(pos); } else if (pos < row->pos()) { + lyxerr << "dont like 3 please report" << endl; pos = row->pos(); cur.pos(pos); }