Summary: | Crashes with some documents on "View differences" when file has changed on disk | ||
---|---|---|---|
Product: | [Applications] kate | Reporter: | Philippe Cloutier <chealer> |
Component: | general | Assignee: | KWrite Developers <kwrite-bugs-null> |
Status: | VERIFIED FIXED | ||
Severity: | crash | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Debian testing | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | Testcase |
Description
Philippe Cloutier
2006-03-19 11:08:09 UTC
Created attachment 15191 [details]
Testcase
Stripped down version of the manpage on which I first experienced the bug.
SVN commit 526984 by dhaumann: fix crash CCBUG:123887 M +7 -2 katedialogs.cpp --- branches/KDE/3.4/kdelibs/kate/part/katedialogs.cpp #526983:526984 @@ -1604,7 +1604,7 @@ uint lastln = m_doc->numLines(); for ( uint l = 0; l < lastln; l++ ) - p->writeStdin( m_doc->textLine( l ), l < lastln ); + p->writeStdin( m_doc->textLine( l ) ); p->closeWhenDone(); } @@ -1616,10 +1616,15 @@ m_tmpfile = new KTempFile(); // put all the data we have in it QString stmp; + bool readData = false; while ( p->readln( stmp, false ) > -1 ) + { *m_tmpfile->textStream() << stmp << endl; + readData = true; + } - p->ackRead(); + if( readData ) + p->ackRead(); } void KateModOnHdPrompt::slotPDone( KProcess *p ) SVN commit 526985 by dhaumann: fix crash in View Difference CCBUG: 123887 M +20 -3 katedialogs.cpp --- branches/KDE/3.5/kdelibs/kate/part/katedialogs.cpp #526984:526985 @@ -1634,7 +1634,7 @@ // Start a KProcess that creates a diff KProcIO *p = new KProcIO(); p->setComm( KProcess::All ); - *p << "diff" << "-ub" << "-" << m_doc->url().path(); + *p << "diff" << "-u" << "-" << m_doc->url().path(); connect( p, SIGNAL(processExited(KProcess*)), this, SLOT(slotPDone(KProcess*)) ); connect( p, SIGNAL(readReady(KProcIO*)), this, SLOT(slotPRead(KProcIO*)) ); @@ -1644,7 +1644,7 @@ uint lastln = m_doc->numLines(); for ( uint l = 0; l < lastln; l++ ) - p->writeStdin( m_doc->textLine( l ), l < lastln ); + p->writeStdin( m_doc->textLine( l ) ); p->closeWhenDone(); } @@ -1656,15 +1656,32 @@ m_tmpfile = new KTempFile(); // put all the data we have in it QString stmp; + bool dataRead = false; while ( p->readln( stmp, false ) > -1 ) + { *m_tmpfile->textStream() << stmp << endl; + dataRead = true; + } - p->ackRead(); + // dominik: only ackRead(), when we *really* read data, otherwise, this slot + // is called initity times, which leads to a crash + if( dataRead ) + p->ackRead(); } void KateModOnHdPrompt::slotPDone( KProcess *p ) { setCursor( ArrowCursor ); + if( ! m_tmpfile ) + { + // dominik: there were only whitespace changes, so that the diff returned by + // diff(1) has 0 bytes. So slotPRead() is never called, as there is + // no data, so that m_tmpfile was never created and thus is NULL. + // NOTE: would be nice, if we could produce a fake-diff, so that kompare + // tells us "The files are identical". Right now, we get an ugly + // "Could not parse diff output". + m_tmpfile = new KTempFile(); + } m_tmpfile->close(); if ( ! p->normalExit() /*|| p->exitStatus()*/ ) SVN commit 526988 by dhaumann: fix crash: only call KProcIO::readAck(), when we really read data. BUG:123887 M +21 -3 katedialogs.cpp --- trunk/KDE/kdelibs/kate/part/katedialogs.cpp #526987:526988 @@ -1716,7 +1716,7 @@ int lastln = m_doc->lines(); for ( int l = 0; l < lastln; ++l ) - p->writeStdin( m_doc->line( l ), l < lastln ); + p->writeStdin( m_doc->line( l ) ); p->closeWhenDone(); } @@ -1728,16 +1728,26 @@ m_tmpfile = new KTempFile(); // put all the data we have in it QString stmp; + bool readData = false; while ( p->readln( stmp, false ) > -1 ) + { *m_tmpfile->textStream() << stmp << endl; + readData = true; + } - p->ackRead(); + // dominik: only ackRead(), when we *really* read data, otherwise, this slot + // is called initity times, which leads to a crash + if( readData ) + p->ackRead(); } void KateModOnHdPrompt::slotPDone( KProcess *p ) { setCursor( Qt::ArrowCursor ); - m_tmpfile->close(); + // dominik: whitespace changes lead to diff with 0 bytes, so that slotPRead is + // never called. Thus, m_tmpfile can be NULL + if( m_tmpfile ) + m_tmpfile->close(); if ( ! p->normalExit() /*|| p->exitStatus()*/ ) { @@ -1748,6 +1758,14 @@ return; } + if ( ! m_tmpfile ) + { + KMessageBox::information( this, + i18n("Besides white space changes the files are identical."), + i18n("Diff Output") ); + return; + } + KRun::runURL( m_tmpfile->name(), "text/x-diff", true ); delete m_tmpfile; m_tmpfile = 0; SVN commit 581699 by dhaumann: Fix crashes in 'View Difference' I wasn't aware that we duplicated the code from kate part to kate app and thus had the same bug in the app, too. CCBUG: 123887 M +16 -2 katemwmodonhddialog.cpp --- branches/KDE/3.5/kdebase/kate/app/katemwmodonhddialog.cpp #581698:581699 @@ -237,15 +237,29 @@ m_tmpfile = new KTempFile(); // put all the data we have in it QString stmp; - while ( p->readln( stmp, false ) > -1 ) + bool dataRead = false; + while ( p->readln( stmp, false ) > -1 ) { *m_tmpfile->textStream() << stmp << endl; + dataRead = true; + } - p->ackRead(); + if (dataRead) + p->ackRead(); } void KateMwModOnHdDialog::slotPDone( KProcess *p ) { setCursor( ArrowCursor ); + if( ! m_tmpfile ) + { + // dominik: there were only whitespace changes, so that the diff returned by + // diff(1) has 0 bytes. So slotPRead() is never called, as there is + // no data, so that m_tmpfile was never created and thus is NULL. + // NOTE: would be nice, if we could produce a fake-diff, so that kompare + // tells us "The files are identical". Right now, we get an ugly + // "Could not parse diff output". + m_tmpfile = new KTempFile(); + } m_tmpfile->close(); if ( ! p->normalExit() /*|| p->exitStatus()*/ ) |