Use a return value instead of just Q_ASSERT - don't crash in production

(cherry picked from commit cb1536aaba)
wilder-portage
Kurt Hindenburg 13 years ago
parent 7778a5e099
commit c8a4fabde9
  1. 6
      src/History.cpp
  2. 4
      src/tests/HistoryTest.cpp

@ -507,7 +507,11 @@ int CompactHistoryScroll::getLines()
int CompactHistoryScroll::getLineLen(int lineNumber)
{
Q_ASSERT(lineNumber >= 0 && lineNumber < _lines.size());
if ((lineNumber < 0) || (lineNumber >= _lines.size())) {
kDebug() << "requested line invalid: 0 < " << lineNumber << " < " <<_lines.size();
Q_ASSERT(lineNumber >= 0 && lineNumber < _lines.size());
return 0;
}
CompactHistoryLine* line = _lines[lineNumber];
//kDebug() << "request for line at address " << line;
return line->getLength();

@ -126,8 +126,8 @@ void HistoryTest::testHistoryScroll()
historyScroll = new CompactHistoryScroll(42);
QVERIFY(historyScroll->hasScroll());
QCOMPARE(historyScroll->getLines(), 0);
// QASSERT catches this - QCOMPARE(historyScroll->getLineLen(0), 0);
// QASSERT catches this - QCOMPARE(historyScroll->getLineLen(10), 0);
QCOMPARE(historyScroll->getLineLen(0), 0);
QCOMPARE(historyScroll->getLineLen(10), 0);
const HistoryType& compactHistoryType = historyScroll->getType();
QCOMPARE(compactHistoryType.isEnabled(), true);

Loading…
Cancel
Save