Bug 95990

Summary: Changing history lines count to 1 causes a crash while scrolling up
Product: [Applications] konsole Reporter: Dmitry Suzdalev <dimsuz>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version: 1.4   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Dmitry Suzdalev 2004-12-29 18:37:00 UTC
Version:           1.4 (using KDE 3.3.0, Gentoo)
Compiler:          gcc version 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)
OS:                Linux (i686) release 2.6.9

Hi! Found this bug recently. Here's the steps to reproduce (sorry, no backtrace :( )

1. Open konsole
2. Press 'Enter' (or do whatever you want) until you can move the history scrollbar (i.e. until some screen lines will go into history). But don't move scrollbar yet.
3. Set the history size to be '1' - one line (in Menu->Settings->History...)
4. Scroll up-up-up, until it crashes :).
5. Voila.

It works for me every time. I tried this steps on two Linuxes - Suse adn Gentoo. Both had KDE-3.3.0 installed.

Hope this info will help you to fix the bug! :)
Comment 1 Kurt Hindenburg 2004-12-31 01:29:04 UTC
Well, after playing around for awhile, I got it to crash...

QGVector::operator[]: Index 1 out of range
QGVector::operator[]: Index 1 out of range

To reproduce, first have the History to > 1 (the default 1000 is O.K.);
do something to produce output in history (ls /dev).
Now, change History to 1; scroll up until it crashes....
Comment 2 Kurt Hindenburg 2004-12-31 03:28:51 UTC
It appears that the # of lines saved is History->Number of lines - 1.  
Example: set number of lines to 10, 9 lines are saved.
set to 1, 0 lines are saved.
set to 2, 1 line is saved.

...etc.
Comment 3 Kurt Hindenburg 2004-12-31 20:54:06 UTC
0x4009c9fd in HistoryScrollBuffer::getLineLen(int) (this=0x807bb24, lineno=1)
    at qgarray.h:79
79          uint        size()   const  { return shd->len; }

It appears that for viewing history is actually History->lines - 1, which causes this error.  Note that for saving history all the lines are saved.

This appears to fix this by having viewing history to actually be history->lines.
Needs testing....

Index: TEHistory.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/TEHistory.cpp,v
retrieving revision 1.25
diff -u -p -r1.25 TEHistory.cpp
--- TEHistory.cpp       28 Jun 2003 10:31:38 -0000      1.25
+++ TEHistory.cpp       31 Dec 2004 19:51:50 -0000
@@ -230,7 +230,8 @@ void HistoryScrollBuffer::addCells(ca a[
      m_buffFilled = true;
     }

-  if (m_nbLines < m_maxNbLines - 1) ++m_nbLines;
+//  if (m_nbLines < m_maxNbLines - 1) ++m_nbLines;
+  if (m_nbLines < m_maxNbLines ) ++m_nbLines; // Fixes BR95990 ?!?

   // m_histBuffer.remove(m_arrayIndex); // not necessary
   m_histBuffer.insert(m_arrayIndex, newLine);

Comment 4 Kurt Hindenburg 2005-01-08 20:28:44 UTC
Comment #3 is not enough to prevent the crashing.

Index: TEHistory.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/TEHistory.cpp,v
retrieving revision 1.25
diff -u -p -r1.25 TEHistory.cpp
--- TEHistory.cpp       28 Jun 2003 10:31:38 -0000      1.25
+++ TEHistory.cpp       8 Jan 2005 19:27:04 -0000
@@ -230,7 +230,7 @@ void HistoryScrollBuffer::addCells(ca a[
      m_buffFilled = true;
     }

-  if (m_nbLines < m_maxNbLines - 1) ++m_nbLines;
+  if (m_nbLines < m_maxNbLines) ++m_nbLines;

   // m_histBuffer.remove(m_arrayIndex); // not necessary
   m_histBuffer.insert(m_arrayIndex, newLine);
@@ -329,6 +329,7 @@ void HistoryScrollBuffer::setMaxNbLines(

 int HistoryScrollBuffer::adjustLineNb(int lineno)
 {
+  if (lineno == 0) return 0;
   if (m_buffFilled)
       return (lineno + m_arrayIndex + 2) % m_maxNbLines;
   else

On another note, changing the history line # to a smaller # when there is text in the buffer is buggy.  Looks like void HistoryScrollBuffer::setMaxNbLines() needs fixed.
Comment 5 Kurt Hindenburg 2005-01-08 22:44:04 UTC
CVS commit by hindenburg: 

Prevent crash when History changed to 1.  Konsole's History needs some TLC.

BUG: 95990


  M +1 -1      TEHistory.cpp   1.26


--- kdebase/konsole/konsole/TEHistory.cpp  #1.25:1.26
@@ -333,5 +333,5 @@ int HistoryScrollBuffer::adjustLineNb(in
       return (lineno + m_arrayIndex + 2) % m_maxNbLines;
   else
-      return lineno + 1;
+      return lineno ? lineno + 1 : 0;
 }