WidgetColorizer: eliminate unsafe QStringView usage
4cbff15f changed the type of the text
local variable from QString
to QStringView
. The underlying QString
is a
temporary returned by QTextFragment::text()
that is destroyed at the end
of the full expression. But the QStringView text
is checked for
emptiness on the next line.
Combine the QStringView
construction and usage into a single line to
make the usage safer. The code did not actually trigger undefined
behavior, because only QStringView::isEmpty()
, which accesses only
QStringView::m_size
, was called on the text
variable. And the trivial
QStringView
destructor does not dereference the dangling pointer
QStringView::m_data
either.
Fixes #52 (closed).
Edited by Igor Kushnir