From c8a4fabde9073256767f905fbbfd8a8e7cc96c7e Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Mon, 2 Sep 2013 21:48:15 -0400 Subject: [PATCH] Use a return value instead of just Q_ASSERT - don't crash in production (cherry picked from commit cb1536aabaf7852432ae14b465d15fd7f9dc94aa) --- src/History.cpp | 6 +++++- src/tests/HistoryTest.cpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/History.cpp b/src/History.cpp index 48e6a4e2..b9df99f5 100644 --- a/src/History.cpp +++ b/src/History.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(); diff --git a/src/tests/HistoryTest.cpp b/src/tests/HistoryTest.cpp index 7ad5acc8..ef1a6e93 100644 --- a/src/tests/HistoryTest.cpp +++ b/src/tests/HistoryTest.cpp @@ -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);