diff --git a/src/qhexedit.cpp b/src/qhexedit.cpp index 9736579..78c13b9 100644 --- a/src/qhexedit.cpp +++ b/src/qhexedit.cpp @@ -995,11 +995,16 @@ void QHexEdit::paintEvent(QPaintEvent *event) if (_editAreaIsAscii) { // every 2 hex there is 1 ascii - int ch = (uchar)_dataShown.at(hexPos / 2); - if (ch < ' ' || ch > '~') - ch = _defaultChar; + int asciiPos = hexPos / 2; + // The cursor can go out of the currently displayed data + if (asciiPos < _dataShown.size()) + { + int ch = (uchar)_dataShown.at(asciiPos); + if (ch < ' ' || ch > '~') + ch = '.'; - painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, QChar(ch)); + painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, QChar(ch)); + } } else {