@@ -70,7 +70,7 @@ void HexWidget::scroll(int value) {
7070 }
7171 }
7272 if (value >= verticalScrollBar ()->maximum ()) {
73- int addr = m_maxOffset + m_base + 1 ;
73+ int addr = m_base + m_size ;
7474 QByteArray data;
7575 for (int i = 0 ; i < m_bytesPerLine && (addr + i) < 0x1000000 ; i++) {
7676 data.append (mem_peek_byte (addr + i));
@@ -118,10 +118,10 @@ int HexWidget::indexOf(const QByteArray &ba) {
118118
119119int HexWidget::indexNotOf (const QByteArray &ba) {
120120 int res = -1 ;
121- QByteArray buffer{m_data.mid (m_cursorOffset, m_maxOffset )};
121+ QByteArray buffer{m_data.mid (m_cursorOffset / 2 )};
122122 std::size_t found = buffer.toStdString ().find_first_not_of (ba.toStdString ());
123123 if (found != std::string::npos) {
124- setOffset (res = static_cast <int >(found));
124+ setOffset (res = static_cast <int >(m_cursorOffset / 2 + found));
125125 }
126126 return res;
127127}
@@ -144,8 +144,8 @@ void HexWidget::setHighlight(const int address) {
144144}
145145
146146void HexWidget::setCursorOffset (int offset, bool selection, bool clearHighlight) {
147- if (offset > m_size * 2 ) {
148- offset = m_size * 2 ;
147+ if (offset >= m_size * 2 ) {
148+ offset = m_size * 2 - 1 ;
149149 }
150150 if (offset < 0 ) {
151151 offset = 0 ;
@@ -213,7 +213,6 @@ void HexWidget::showCursor() {
213213
214214void HexWidget::adjust () {
215215 m_size = m_data.size ();
216- m_maxOffset = m_size - 1 ;
217216
218217 m_charWidth = fontMetrics ().horizontalAdvance (QLatin1Char (' D' ));
219218 m_charHeight = fontMetrics ().height ();
@@ -234,20 +233,20 @@ void HexWidget::adjust() {
234233 horizontalScrollBar ()->setRange (0 , xWidth - viewport ()->width ());
235234 horizontalScrollBar ()->setPageStep (viewport ()->width ());
236235
237- int rows = m_size / m_bytesPerLine;
236+ int rows = ( m_size + m_bytesPerLine - 1 ) / m_bytesPerLine;
238237 int visibleHeight = viewport ()->height () - m_gap;
239238 if (horizontalScrollBar ()->isVisible ()) {
240239 visibleHeight -= horizontalScrollBar ()->height ();
241240 }
242241 m_visibleRows = visibleHeight / m_charHeight;
243- verticalScrollBar ()->setRange (0 , rows - m_visibleRows);
242+ verticalScrollBar ()->setRange (0 , rows - m_visibleRows - 1 );
244243 verticalScrollBar ()->setPageStep (m_visibleRows);
245244
246245 int lines = verticalScrollBar ()->value ();
247246 m_lineStart = lines * m_bytesPerLine;
248247 m_lineEnd = m_lineStart + m_visibleRows * m_bytesPerLine - 1 ;
249248 if (m_lineEnd >= m_size) {
250- m_lineEnd = m_maxOffset ;
249+ m_lineEnd = m_size - 1 ;
251250 }
252251
253252 int x, y = (((m_cursorOffset / 2 ) - m_lineStart) / m_bytesPerLine + 1 ) * m_charHeight;
@@ -363,9 +362,7 @@ void HexWidget::paintEvent(QPaintEvent *event) {
363362 if (addr + m_base > 0xffffff ) { break ; }
364363 painter.setPen (cText);
365364 painter.drawText (xAddr, y, int2hex (m_base + lineAddr, 6 ));
366- for (int col = 0 ; col < m_bytesPerLine && addr < m_maxOffset; col++) {
367- addr = lineAddr + col;
368-
365+ for (int col = 0 ; col < m_bytesPerLine && addr < m_size; col++, addr++) {
369366 painter.setPen (cText);
370367 uint8_t data = static_cast <uint8_t >(m_data[addr]);
371368 uint8_t flags = debug.addr [addr + m_base];
0 commit comments