diff --git a/crengine/src/lvtextfm.cpp b/crengine/src/lvtextfm.cpp index 1ba07479f..ef3a0ad22 100644 --- a/crengine/src/lvtextfm.cpp +++ b/crengine/src/lvtextfm.cpp @@ -1081,10 +1081,12 @@ class LVFormatter { // (it will allow wrap before and after an object, unless it's near // some punctuation/quote/paren, whose rules will be ensured it seems). int brk = lb_process_next_char(&lbCtx, (utf32_t)0xFFFC); // OBJECT REPLACEMENT CHARACTER - if (brk == LINEBREAK_ALLOWBREAK) - m_flags[pos-1] |= LCHAR_ALLOW_WRAP_AFTER; - else - m_flags[pos-1] &= ~LCHAR_ALLOW_WRAP_AFTER; + if (pos > 0) { + if (brk == LINEBREAK_ALLOWBREAK) + m_flags[pos-1] |= LCHAR_ALLOW_WRAP_AFTER; + else + m_flags[pos-1] &= ~LCHAR_ALLOW_WRAP_AFTER; + } #else m_flags[pos] |= LCHAR_ALLOW_WRAP_AFTER; #endif @@ -1102,10 +1104,12 @@ class LVFormatter { #if (USE_LIBUNIBREAK==1) // Let libunibreak know there was an object int brk = lb_process_next_char(&lbCtx, (utf32_t)0xFFFC); // OBJECT REPLACEMENT CHARACTER - if (brk == LINEBREAK_ALLOWBREAK) - m_flags[pos-1] |= LCHAR_ALLOW_WRAP_AFTER; - else - m_flags[pos-1] &= ~LCHAR_ALLOW_WRAP_AFTER; + if (pos > 0) { + if (brk == LINEBREAK_ALLOWBREAK) + m_flags[pos-1] |= LCHAR_ALLOW_WRAP_AFTER; + else + m_flags[pos-1] &= ~LCHAR_ALLOW_WRAP_AFTER; + } #else m_flags[pos] |= LCHAR_ALLOW_WRAP_AFTER; #endif