]> git.lyx.org Git - features.git/commitdiff
Fix FontIterator to not access pos >= par.size()
authorVincent van Ravesteijn <vfr@lyx.org>
Sun, 28 Apr 2013 12:44:08 +0000 (14:44 +0200)
committerVincent van Ravesteijn <vfr@lyx.org>
Sun, 28 Apr 2013 17:12:16 +0000 (19:12 +0200)
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 f5ad0c128aec (Jean-Marc Lasgouttes; Get rid of
annoying warning message).

src/Paragraph.cpp
src/TextMetrics.cpp

index ded92f505e698a7a0a78ee24bb5356d80100d66c..6fc44a0d75f382a1c1ab73f283b89ed5b31efcc0 100644 (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();
index d0f9b3d83ef404b7b78703441f6d7887eef13fb8..4e70dc0b82091b5b207a45e49d8f3c43d648796d 100644 (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;
                }