QPlainTextEdit: make sure firstVisibleBlock() is valid

Under some circumstances it's possible that firstVisibleBlock() returns
an invalid block within QPlainTextEditPrivate::_q_textChanged() which
results in a nullptr access later on.
Therefore add a check similar to other places and test the validity of
the returned block before accessing it.

Fixes: QTBUG-80929
Change-Id: I1fd4643b10b842acfe1c356048379f0ba225dddf
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-12-22 17:53:20 +01:00
parent 02ddf08db8
commit c623334248

View File

@ -839,7 +839,8 @@ void QPlainTextEditPrivate::_q_textChanged()
placeholderVisible = !placeholderText.isEmpty() placeholderVisible = !placeholderText.isEmpty()
&& q->document()->isEmpty() && q->document()->isEmpty()
&& q->firstVisibleBlock().layout()->preeditAreaText().isEmpty(); && (!q->firstVisibleBlock().isValid() ||
q->firstVisibleBlock().layout()->preeditAreaText().isEmpty());
if (placeholderCurrentyVisible != placeholderVisible) if (placeholderCurrentyVisible != placeholderVisible)
viewport->update(); viewport->update();