Fix FontIterator to not access pos >= par.size()

An iterator is typicall incremented passed the valid data into the 'end'
state. However, if this means that other functions are called with invalid
parameter, we should fix this.

This explains why fontSpan was called with pos==size() while this was not
expected to happen.

This patch reverts partly f5ad0c128a (Jean-Marc Lasgouttes; Get rid of
annoying warning message).
This commit is contained in:
Vincent van Ravesteijn 2013-04-28 14:44:08 +02:00
parent e115b006e6
commit 88eae06611
2 changed files with 2 additions and 8 deletions

View File

@ -1830,13 +1830,7 @@ Font const & Paragraph::getFontSettings(BufferParams const & bparams,
FontSpan Paragraph::fontSpan(pos_type pos) const
{
LBUFERR(pos <= size());
// Last position is a special case. I suspect that it would
// actually make sense to extend the last font span to cover
// the last character (JMarc)
if (pos == size())
return FontSpan(pos, pos);
LBUFERR(pos < size());
pos_type start = 0;
FontList::const_iterator cit = d->fontlist_.begin();

View File

@ -771,7 +771,7 @@ public:
FontIterator & operator++()
{
++pos_;
if (pos_ > endspan_ || pos_ == bodypos_) {
if (pos_ < par_.size() && (pos_ > endspan_ || pos_ == bodypos_)) {
font_ = tm_.displayFont(pit_, pos_);
endspan_ = par_.fontSpan(pos_).last;
}