In the "shortcut: try last block first" branch in TextBuffer::blockForLine(),
m_lastUsedBlock is accessed multiple times. If another tread simultaneously
executes the binary block search below in the same function, then
m_lastUsedBlock may be modified by that thread. This may result in the first
thread returning a wrong block, since it may return the modified value of
m_lastUsedBlock instead of the original value that it used to determine whether
the given line is in the block.
Also, it seems like it may be safer to use std::atomic for m_lastUsedBlock,
but I am not sure about that.
This change is intended to fix a crash where an out-of-bounds line is accessed
in katetextblock.cpp, which occurs about one or two times per month for me when
using KDevelop. I have no idea whether this possible race condition is actually
the reason for these crashes, but it seems like a plausible candidate.