Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4d4a7d52 authored by Michael Reeves's avatar Michael Reeves

Use Q_ASSERT. Don't assert(false);

parent 15b91930
......@@ -102,7 +102,7 @@ QString safeStringJoin(const QStringList& sl, char sepChar, char metaChar)
// If a string contains the separator character, it will be replaced with "\,".
// Any occurances of "\" (one backslash) will be replaced with "\\" (2 backslashes)
assert(sepChar != metaChar);
Q_ASSERT(sepChar != metaChar);
QString sep;
sep += sepChar;
......@@ -128,7 +128,7 @@ QString safeStringJoin(const QStringList& sl, char sepChar, char metaChar)
// Split a string that was joined with safeStringJoin
QStringList safeStringSplit(const QString& s, char sepChar, char metaChar)
{
assert(sepChar != metaChar);
Q_ASSERT(sepChar != metaChar);
QStringList sl;
// Miniparser
int i = 0;
......
......@@ -20,7 +20,6 @@
#include <QAtomicInt>
#include <QString>
#include <assert.h>
#include <map>
template< class T >
......@@ -61,7 +60,7 @@ T max3( T d1, T d2, T d3 )
template <class T>
T minMaxLimiter( T d, T minimum, T maximum )
{
assert(minimum<=maximum);
Q_ASSERT(minimum<=maximum);
if ( d < minimum ) return minimum;
if ( d > maximum ) return maximum;
return d;
......
......@@ -35,7 +35,6 @@
#include <QTextCodec>
#include <QTextStream>
#include <assert.h>
#include <ctype.h>
#include <map>
//using namespace std;
......@@ -946,7 +945,7 @@ void SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
bNonWhiteFound = true;
}
}
assert(lineIdx == lines);
Q_ASSERT(lineIdx == lines);
m_vSize = lines;
}
......@@ -1082,7 +1081,7 @@ void SourceData::FileData::removeComments()
}
// end of line
assert(isLineOrBufEnd(p, i, size));
Q_ASSERT(isLineOrBufEnd(p, i, size));
m_v[line].bContainsPureComment = bCommentInLine && bWhite;
/* std::cout << line << " : " <<
( bCommentInLine ? "c" : " " ) <<
......@@ -1149,10 +1148,8 @@ void calcDiff3LineListUsingAB(
--d.diff2;
++lineB;
}
else if(d.nofEquals < 0)
{
assert(false);
}
Q_ASSERT(d.nofEquals >= 0);
d3ll.push_back(d3l);
}
......@@ -1267,12 +1264,12 @@ void calcDiff3LineListUsingBC(
while(i3c != d3ll.end() && (*i3c).lineC != lineC)
++i3c;
assert(i3b != d3ll.end());
assert(i3c != d3ll.end());
Q_ASSERT(i3b != d3ll.end());
Q_ASSERT(i3c != d3ll.end());
if(i3b == i3c)
{
assert((*i3b).lineC == lineC);
Q_ASSERT((*i3b).lineC == lineC);
(*i3b).bBEqC = true;
}
else
......@@ -1285,7 +1282,7 @@ void calcDiff3LineListUsingBC(
Diff3LineList::iterator i3b1 = i3b;
while(i3c1 != i3b && i3b1 != i3c)
{
assert(i3b1 != d3ll.end() || i3c1 != d3ll.end());
Q_ASSERT(i3b1 != d3ll.end() || i3c1 != d3ll.end());
if(i3c1 != d3ll.end()) ++i3c1;
if(i3b1 != d3ll.end()) ++i3b1;
}
......@@ -1577,7 +1574,7 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
{
Diff d(0, 0, 0);
d.nofEquals = e->line0 - currentLine1;
assert(d.nofEquals == e->line1 - currentLine2);
Q_ASSERT(d.nofEquals == e->line1 - currentLine2);
d.diff1 = e->deleted;
d.diff2 = e->inserted;
currentLine1 += d.nofEquals + d.diff1;
......@@ -1642,7 +1639,6 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
}
}
#ifndef NDEBUG
// Verify difflist
{
int l1 = 0;
......@@ -1655,10 +1651,8 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
}
//if( l1!=p1-p1start || l2!=p2-p2start )
if(l1 != size1 || l2 != size2)
assert(false);
Q_ASSERT(l1 == size1 && l2 == size2);
}
#endif
pp.setCurrent(1.0);
......@@ -2335,7 +2329,6 @@ void calcDiff(const T* p1, int size1, const T* p2, int size2, DiffList& diffList
break;
}
#ifndef NDEBUG
// Verify difflist
{
int l1 = 0;
......@@ -2347,11 +2340,8 @@ void calcDiff(const T* p1, int size1, const T* p2, int size2, DiffList& diffList
l2 += i->nofEquals + i->diff2;
}
//if( l1!=p1-p1start || l2!=p2-p2start )
if(l1 != size1 || l2 != size2)
assert(false);
Q_ASSERT(l1 == size1 && l2 == size2);
}
#endif
}
bool fineDiff(
......@@ -2372,6 +2362,8 @@ bool fineDiff(
int listIdx = 0;
for(i = diff3LineList.begin(); i != diff3LineList.end(); ++i)
{
Q_ASSERT(selector = 1 || selector == 2 || selector == 3);
if(selector == 1) {
k1 = i->lineA;
k2 = i->lineB;
......@@ -2386,8 +2378,7 @@ bool fineDiff(
k1 = i->lineC;
k2 = i->lineA;
}
else
assert(false);
if((k1 == -1 && k2 != -1) || (k1 != -1 && k2 == -1)) bTextsTotalEqual = false;
if(k1 != -1 && k2 != -1)
{
......@@ -2419,6 +2410,7 @@ bool fineDiff(
}
}
Q_ASSERT(selector = 1 || selector == 2 || selector == 3);
if(selector == 1) {
delete(*i).pFineAB;
(*i).pFineAB = pDiffList;
......@@ -2433,12 +2425,12 @@ bool fineDiff(
delete(*i).pFineCA;
(*i).pFineCA = pDiffList;
}
else
assert(false);
}
if((v1[k1].bContainsPureComment || v1[k1].whiteLine()) && (v2[k2].bContainsPureComment || v2[k2].whiteLine()))
{
Q_ASSERT(selector = 1 || selector == 2 || selector == 3);
if(selector == 1) {
i->bAEqB = true;
}
......@@ -2450,8 +2442,6 @@ bool fineDiff(
{
i->bAEqC = true;
}
else
assert(false);
}
}
++listIdx;
......@@ -2470,5 +2460,5 @@ void calcDiff3LineVector(Diff3LineList& d3ll, Diff3LineVector& d3lv)
{
d3lv[j] = &(*i);
}
assert(j == (int)d3lv.size());
Q_ASSERT(j == (int)d3lv.size());
}
......@@ -21,7 +21,6 @@
#include <QPainter>
#include <QLinkedList>
#include <QVector>
#include <assert.h>
#include "common.h"
#include "fileaccess.h"
#include "options.h"
......@@ -122,7 +121,7 @@ struct Diff3Line
const LineData* getLineData( int src ) const
{
assert( m_pDiffBufferInfo!=nullptr );
Q_ASSERT( m_pDiffBufferInfo!=nullptr );
if ( src == 1 && lineA >= 0 ) return &m_pDiffBufferInfo->m_pLineDataA[lineA];
if ( src == 2 && lineB >= 0 ) return &m_pDiffBufferInfo->m_pLineDataB[lineB];
if ( src == 3 && lineC >= 0 ) return &m_pDiffBufferInfo->m_pLineDataC[lineC];
......
......@@ -41,7 +41,6 @@
#include <KLocalizedString>
#include <assert.h>
#include <cmath>
#include <cstdlib>
......@@ -678,7 +677,7 @@ void DiffTextWindow::convertToLinePos(int x, int y, int& line, int& pos)
int Selection::firstPosInLine(int l)
{
assert(firstLine != -1);
Q_ASSERT(firstLine != -1);
int l1 = firstLine;
int l2 = lastLine;
......@@ -699,7 +698,7 @@ int Selection::firstPosInLine(int l)
int Selection::lastPosInLine(int l)
{
assert(firstLine != -1);
Q_ASSERT(firstLine != -1);
int l1 = firstLine;
int l2 = lastLine;
......@@ -1275,6 +1274,8 @@ void DiffTextWindowData::getLineInfo(
bool bAEqB = d3l.bAEqB || (d3l.bWhiteLineA && d3l.bWhiteLineB);
bool bAEqC = d3l.bAEqC || (d3l.bWhiteLineA && d3l.bWhiteLineC);
bool bBEqC = d3l.bBEqC || (d3l.bWhiteLineB && d3l.bWhiteLineC);
Q_ASSERT(m_winIdx >= 1 && m_winIdx <= 3);
if(m_winIdx == 1) {
lineIdx = d3l.lineA;
pFineDiff1 = d3l.pFineAB;
......@@ -1301,8 +1302,7 @@ void DiffTextWindowData::getLineInfo(
((d3l.lineB == -1) != (lineIdx == -1) ? 2 : 0);
changed2 |= (bAEqC ? 0 : 1) + (bBEqC ? 0 : 2);
}
else
assert(false);
}
void DiffTextWindow::resizeEvent(QResizeEvent* e)
......@@ -1347,6 +1347,9 @@ QString DiffTextWindow::getSelection()
for(it = 0; it < vectorSize; ++it)
{
const Diff3Line* d3l = d->m_bWordWrap ? d->m_diff3WrapLineVector[it].pD3L : (*d->m_pDiff3LineVector)[it];
Q_ASSERT(d->m_winIdx >= 1 && d->m_winIdx <= 3);
if(d->m_winIdx == 1) {
lineIdx = d3l->lineA;
}
......@@ -1358,8 +1361,6 @@ QString DiffTextWindow::getSelection()
{
lineIdx = d3l->lineC;
}
else
assert(false);
if(lineIdx != -1)
{
......@@ -1774,7 +1775,7 @@ void DiffTextWindow::recalcWordWrapHelper(int wrapLineVectorSize, int visibleTex
Diff3Line& d3l = *(*d->m_pDiff3LineVector)[i];
if(d3l.linesNeededForDisplay < linesNeeded)
{
assert(wrapLineVectorSize == 0);
Q_ASSERT(wrapLineVectorSize == 0);
d3l.linesNeededForDisplay = linesNeeded;
}
......
......@@ -24,7 +24,6 @@
#include "progress.h"
#include <algorithm>
#include <assert.h>
#include <map>
#include <vector>
......@@ -588,7 +587,7 @@ QVariant DirectoryMergeWindow::Data::data(const QModelIndex& index, int role) co
return i18n("Error: Dates are equal but files are not.");
break;
default:
assert(false);
Q_ASSERT(true);
break;
}
}
......@@ -1588,7 +1587,7 @@ void DirectoryMergeWindow::Data::compareFilesAndCalcAges(MergeFileInfos& mfi)
if(mfi.dirA() != mfi.dirC()) mfi.m_bEqualAC = false;
if(mfi.dirB() != mfi.dirC()) mfi.m_bEqualBC = false;
assert(eNew == 0 && eMiddle == 1 && eOld == 2);
Q_ASSERT(eNew == 0 && eMiddle == 1 && eOld == 2);
// The map automatically sorts the keys.
int age = eNew;
......@@ -1966,7 +1965,7 @@ void DirectoryMergeWindow::Data::calcSuggestedOperation(const QModelIndex& mi, e
eDefaultMergeOp = eMergeABToDest;
}
if(eDefaultMergeOp == eMergeToAB && bCheckC) {
assert(false);
Q_ASSERT(true);
}
if(eDefaultMergeOp == eMergeToA || eDefaultMergeOp == eMergeToB ||
......@@ -2015,7 +2014,6 @@ void DirectoryMergeWindow::Data::calcSuggestedOperation(const QModelIndex& mi, e
else //if ( !mfi.existsInA() && !mfi.existsInB() )
{
setMergeOperation(mi, eNoOperation);
assert(false);
}
}
else
......@@ -2071,7 +2069,6 @@ void DirectoryMergeWindow::Data::calcSuggestedOperation(const QModelIndex& mi, e
else //if ( !mfi.existsInA() && !mfi.existsInB() && !mfi.existsInC() )
{
setMergeOperation(mi, eNoOperation);
assert(false);
}
}
......@@ -2126,8 +2123,10 @@ void DirectoryMergeWindow::Data::calcSuggestedOperation(const QModelIndex& mi, e
case eMergeToAB:
case eMergeABCToDest:
case eMergeABToDest:
break;
default:
assert(false);
Q_ASSERT(true);
break;
}
setMergeOperation(mi, eMO);
}
......@@ -2631,7 +2630,6 @@ bool DirectoryMergeWindow::Data::executeMergeOperation(MergeFileInfos& mfi, bool
break;
default:
KMessageBox::error(q, i18n("Unknown merge operation. (This must never happen!)"), i18n("Error"));
assert(false);
}
bool bSuccess = false;
......@@ -2677,7 +2675,6 @@ bool DirectoryMergeWindow::Data::executeMergeOperation(MergeFileInfos& mfi, bool
break;
default:
KMessageBox::error(q, i18n("Unknown merge operation."), i18n("Error"));
assert(false);
}
return bSuccess;
......
......@@ -35,7 +35,7 @@ namespace KDiff3 {
const char* slot,
KActionCollection* ac,
const char* actionName) {
assert( ac != nullptr );
Q_ASSERT( ac != nullptr );
QAction * theAction = ac->addAction( actionName );
theAction->setText( text );
QObject::connect( theAction, SIGNAL( triggered() ), receiver, slot );
......@@ -48,7 +48,7 @@ namespace KDiff3 {
const char* slot,
KActionCollection* ac,
const char* actionName) {
assert( ac != nullptr );
Q_ASSERT( ac != nullptr );
KToggleAction* theAction = new KToggleAction(ac);
ac->addAction( actionName, theAction );
theAction->setText( text );
......
......@@ -1041,7 +1041,7 @@ void KDiff3App::slotFileQuit()
void KDiff3App::slotViewToolBar()
{
assert(viewToolBar != nullptr);
Q_ASSERT(viewToolBar != nullptr);
slotStatusMsg(i18n("Toggling toolbar..."));
m_pOptions->m_bShowToolBar = viewToolBar->isChecked();
///////////////////////////////////////////////////////////////////
......
......@@ -19,8 +19,6 @@
#include "kreplacements.h"
#include "common.h"
#include <assert.h>
#include <Qt> //namespace
#include <QMessageBox>
#include <QMenu>
......@@ -933,7 +931,7 @@ QString KCmdLineArgs::getOption( const QString& s )
return s_vOption[j].isEmpty() ? QString() : s_vOption[j].last();
}
}
assert(false);
return QString();
}
......@@ -953,7 +951,6 @@ QStringList KCmdLineArgs::getOptionList( const QString& s )
}
}
assert(false);
return QStringList();
}
......@@ -969,7 +966,7 @@ bool KCmdLineArgs::isSet(const QString& s)
return ! s_vOption[j].isEmpty();
}
}
assert(false);
return false;
}
......
......@@ -16,7 +16,6 @@
***************************************************************************/
#include "merger.h"
#include <assert.h>
Merger::Merger(const DiffList* pDiffListAB, const DiffList* pDiffListCA)
: md1(pDiffListAB, 0), md2(pDiffListCA, 1)
......
......@@ -36,7 +36,7 @@
#include <QTextLayout>
#include <QTextStream>
#include <QUrl>
//Added by qt3to4:
#include <QDropEvent>
#include <QEvent>
#include <QFocusEvent>
......@@ -253,7 +253,7 @@ void mergeOneLine(
bConflict = true;
}
else
assert(false);
Q_ASSERT(true);
}
else if(d.lineA != -1 && d.lineB != -1 && d.lineC == -1)
{
......@@ -313,7 +313,7 @@ void mergeOneLine(
src = C;
}
else
assert(false);
Q_ASSERT(true);
}
bool MergeResultWindow::sameKindCheck(const MergeLine& ml1, const MergeLine& ml2)
......@@ -643,7 +643,7 @@ bool MergeResultWindow::checkOverviewIgnore(MergeLineList::iterator& i)
// Go to prev/next delta/conflict or first/last delta.
void MergeResultWindow::go(e_Direction eDir, e_EndPoint eEndPoint)
{
assert(eDir == eUp || eDir == eDown);
Q_ASSERT(eDir == eUp || eDir == eDown);
MergeLineList::iterator i = m_currentMergeLineIt;
bool bSkipWhiteConflicts = !m_pOptions->m_bShowWhiteSpace;
if(eEndPoint == eEnd)
......@@ -1637,7 +1637,7 @@ QString MergeResultWindow::MergeEditLine::getString(const MergeResultWindow* mrw
}
const Diff3Line& d3l = *m_id3l;
const LineData* pld = nullptr;
assert(src == A || src == B || src == C);
Q_ASSERT(src == A || src == B || src == C);
if(src == A && d3l.lineA != -1)
pld = &mrw->m_pldA[d3l.lineA];
else if(src == B && d3l.lineB != -1)
......@@ -1645,9 +1645,9 @@ QString MergeResultWindow::MergeEditLine::getString(const MergeResultWindow* mrw
else if(src == C && d3l.lineC != -1)
pld = &mrw->m_pldC[d3l.lineC];
//Not an error.
if(pld == nullptr)
{
// assert(false); This is no error.
return QString();
}
......@@ -1845,7 +1845,7 @@ void MergeResultWindow::writeLine(
if(m_cursorYPos == line) m_cursorXPos = 0;
}
else
assert(false);
Q_ASSERT(true);
xOffset -= fm.width('0');
p.setPen(m_pOptions->m_fgColor);
......@@ -1951,7 +1951,7 @@ void MergeResultWindow::paintEvent(QPaintEvent*)
if(line != m_nofLines)
{
m_nofLines = line;
assert(m_nofLines == m_totalSize);
Q_ASSERT(m_nofLines == m_totalSize);
emit resizeSignal();
}
......@@ -2656,7 +2656,6 @@ void MergeResultWindow::calcIteratorFromLineNr(
}
}
}
assert(false);
}
QString MergeResultWindow::getSelection()
......@@ -3183,7 +3182,7 @@ void Overview::drawColumn(QPainter& p, e_OverviewMode eOverviewMode, int x, int
c = m_pOptions->m_colorForConflict;
break;
default:
assert(false);
Q_ASSERT(true);
break;
}
}
......
......@@ -70,7 +70,7 @@ class OptionItem
public:
OptionItem(OptionDialog* pOptionDialog, const QString& saveName)
{
assert(pOptionDialog != nullptr);
Q_ASSERT(pOptionDialog != nullptr);
pOptionDialog->addOptionItem(this);
m_saveName = saveName;
m_bPreserved = false;
......
......@@ -48,15 +48,13 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <assert.h>
#include "fileaccess.h"
#include "kdiff3.h"
#include "optiondialog.h"
#include "progress.h"
#ifdef Q_OS_WIN
#include <windows.h>
#else
#else //TODO:Why?
#include <kshortcutsdialog.h>
#include <unistd.h>
#endif
......@@ -73,14 +71,14 @@ static void debugLineCheck(Diff3LineList& d3ll, int size, int idx)
for(it = d3ll.begin(); it != d3ll.end(); ++it)
{
int l = 0;
Q_ASSERT(idx >= 1 && idx <= 3);
if(idx == 1)
l = (*it).lineA;
else if(idx == 2)
l = (*it).lineB;
else if(idx == 3)
l = (*it).lineC;
else
assert(false);
l = (*it).lineC;
if(l != -1)
{
......@@ -90,7 +88,7 @@ static void debugLineCheck(Diff3LineList& d3ll, int size, int idx)
"Data loss error:\n"
"If it is reproducible please contact the author.\n"),
i18n("Severe Internal Error"));
assert(false);
fprintf(stderr, "Severe Internal Error.\n");
::exit(-1);
}
......@@ -104,7 +102,7 @@ static void debugLineCheck(Diff3LineList& d3ll, int size, int idx)
"Data loss error:\n"
"If it is reproducible please contact the author.\n"),
i18n("Severe Internal Error"));
assert(false);
fprintf(stderr, "Severe Internal Error.\n");
::exit(-1);
}
......
......@@ -29,16 +29,16 @@ bool FileAccess::isValid() const
// bool isSymLink() const;
bool FileAccess::exists() const
{
assert(FALSE);
}
qint64 FileAccess::size() const
{
assert(FALSE);
}
qint64 FileAccess::sizeForReading()
{
assert(FALSE);
}
// bool isReadable() const;
......@@ -55,7 +55,7 @@ qint64 FileAccess::sizeForReading()
// QString filePath() const; // The path-string that was used during construction
QString FileAccess::prettyAbsPath() const
{
assert(FALSE);
}
// KUrl url() const;
QString FileAccess::absoluteFilePath() const
......@@ -70,11 +70,11 @@ bool FileAccess::isLocal() const
bool FileAccess::readFile(void* pDestBuffer, unsigned long maxLength )
{
assert(FALSE);
}
bool FileAccess::writeFile(const void* pSrcBuffer, unsigned long length )
{
assert(FALSE);
}
// bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden,
......@@ -82,26 +82,26 @@ bool FileAccess::writeFile(const void* pSrcBuffer, unsigned long length )
// const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore );
bool FileAccess::copyFile( const QString& destUrl )
{
assert(FALSE);
}
// bool createBackup( const QString& bakExtension );
//
QString FileAccess::tempFileName()
{
assert(FALSE);
}
bool FileAccess::removeTempFile( const QString& )
{
assert(FALSE);
}
/*bool FileAccess::removeFile()
{
assert(FALSE);
}*/
bool FileAccess::removeFile( const QString& )
{
assert(FALSE);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment