From 2496f8e3f3cb1cbfffd664c9b5d7983dc192887b Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 7 Feb 2018 20:18:15 +0000 Subject: Restore assert when GetCharacterInfo is called on an empty edit. CFWL_Edit::UpdateCursorRect now checks if the edit is empty before getting the caret position. Bug: chromium:592750 Change-Id: I792e90537741a78141fa084a646380bfe7ce4637 Reviewed-on: https://pdfium-review.googlesource.com/25910 Reviewed-by: dsinclair Commit-Queue: Henrique Nakashima --- xfa/fde/cfde_texteditengine.cpp | 4 +++- xfa/fwl/cfwl_edit.cpp | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'xfa') diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp index 75fd103b3c..d085a8d147 100644 --- a/xfa/fde/cfde_texteditengine.cpp +++ b/xfa/fde/cfde_texteditengine.cpp @@ -1071,8 +1071,10 @@ std::pair CFDE_TextEditEngine::GetCharacterInfo( if (it->nStart <= start_idx && start_idx < it->nStart + it->nCount) break; } - if (it == text_piece_info_.end()) + if (it == text_piece_info_.end()) { + NOTREACHED(); return {0, CFX_RectF()}; + } return {it->nBidiLevel, GetCharRects(*it)[start_idx - it->nStart]}; } diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index 051c39f74e..b98278c622 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -1075,10 +1075,15 @@ void CFWL_Edit::InitCaret() { } void CFWL_Edit::UpdateCursorRect() { - int32_t bidi_level = 0; - m_rtCaret = CFX_RectF(); - std::tie(bidi_level, m_rtCaret) = - m_EdtEngine.GetCharacterInfo(m_CursorPosition); + int32_t bidi_level; + if (m_EdtEngine.GetLength() > 0) { + std::tie(bidi_level, m_rtCaret) = + m_EdtEngine.GetCharacterInfo(m_CursorPosition); + } else { + bidi_level = 0; + m_rtCaret = CFX_RectF(); + } + // TODO(dsinclair): This should handle bidi level ... m_rtCaret.width = 1.0f; -- cgit v1.2.3