author | erik <erik> | 2007-01-26 20:22:50 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-26 20:22:50 (UTC) |
commit | 53d630c9c4813142ee13e6843c30476a5db26e78 (patch) (side-by-side diff) | |
tree | 50a77a94cfeaccbb3d993bced8b7d0f498f74c7c | |
parent | 152a8fe978851aea8dac6ae5cb11f73540746b83 (diff) | |
download | opie-53d630c9c4813142ee13e6843c30476a5db26e78.zip opie-53d630c9c4813142ee13e6843c30476a5db26e78.tar.gz opie-53d630c9c4813142ee13e6843c30476a5db26e78.tar.bz2 |
Each file in this commit exhibit an example of what prevent calls
'reverse inull'. All that means is that a pointer gets dereferenced. Then
a pointer gets checked for validity before being dereferenced again. This
almost always points to shenanigans.
For example, the konsole.cpp file has this konsoleInit() call which passes
in a const char** shell variable. Since it is a double pointer the programmer
who wrote the code made the mistake of mixing the checking of the pointer
and the pointer that points to the pointer. This commit attempts to correct
that.
Of course there are other instances of the same thing. But they all boil
down to a small mistake which might have produced strange side effects.
-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 10 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 100 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 2 |
4 files changed, 49 insertions, 65 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index f4ca0bf..5c40569 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp @@ -219,6 +219,12 @@ static void konsoleInit(const char** shell) { + if (!shell) { + owarn << "No double pointer 'shell'" << oendl; + return; + } + *shell = getenv("SHELL"); - owarn << "SHell initially is " << *shell << "" << oendl; + if (*shell) + owarn << "Current shell: " << *shell << "" << oendl; - if (shell == NULL || *shell == '\0') { + if (*shell == NULL || **shell == '\0') { struct passwd *ent = 0; diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 61beac5..4bbc62b 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -852,13 +852,2 @@ bool TextEdit::saveAs() { odebug << "saveAsFile " + currentFileName << oendl; - // case of nothing to save... -// if ( !doc && !currentFileName.isEmpty()) { -// //|| !bFromDocView) -// odebug << "no doc" << oendl; -// return true; -// } -// if ( !editor->edited() ) { -// delete doc; -// doc = 0; -// return true; -// } @@ -869,5 +858,5 @@ bool TextEdit::saveAs() { || currentFileName == tr("Unnamed") - || currentFileName == tr("Text Editor")) { + || currentFileName == tr("Text Editor")) + { odebug << "do silly TT filename thing" << oendl; -// if ( doc && doc->name().isEmpty() ) { QString pt = rt.simplifyWhiteSpace(); @@ -875,5 +864,4 @@ bool TextEdit::saveAs() { QString docname = pt; - if ( i > 0 ) - docname = pt.left( i ); - // remove "." at the beginning + if ( i > 0 ) docname = pt.left( i ); + while( docname.startsWith( "." ) ) @@ -881,13 +869,11 @@ bool TextEdit::saveAs() { docname.replace( QRegExp("/"), "_" ); - // cut the length. filenames longer than that - //don't make sense and something goes wrong when they get too long. - if ( docname.length() > 40 ) - docname = docname.left(40); - if ( docname.isEmpty() ) - docname = tr("Unnamed"); + // Cut the length. Filenames longer than 40 are not helpful + // and something goes wrong when they get too long. + if ( docname.length() > 40 ) docname = docname.left(40); + + if ( docname.isEmpty() ) docname = tr("Unnamed"); + if(doc) doc->setName(docname); + currentFileName=docname; -// } -// else -// odebug << "hmmmmmm" << oendl; } @@ -908,8 +894,7 @@ bool TextEdit::saveAs() { dire = QPEApplication::documentDir(); + QString str; if( !featureAutoSave) { - str = OFileDialog::getSaveFileName( 2, - dire, - filee, map); - } else + str = OFileDialog::getSaveFileName( 2, dire, filee, map); + } else str = currentFileName; @@ -923,31 +908,26 @@ bool TextEdit::saveAs() { if(doc) -// QString file = doc->file(); -// doc->removeFiles(); delete doc; - DocLnk nf; - nf.setType("text/plain"); - nf.setFile( fileNm); - doc = new DocLnk(nf); -// editor->setText(rt); - odebug << "Saving file as "+currentFileName << oendl; - doc->setName( fi.baseName() /*currentFileName*/); - updateCaption( currentFileName); - - FileManager fm; - if ( !fm.saveFile( *doc, rt ) ) { - QMessageBox::message(tr("Text Edit"),tr("Save Failed")); - return false; - } - - if( filePerms ) { - filePermissions *filePerm; - filePerm = new filePermissions(this, - tr("Permissions"),true, - 0,(const QString &)fileNm); - QPEApplication::execDialog( filePerm ); - - if( filePerm) - delete filePerm; - } -// } + + DocLnk nf; + nf.setType("text/plain"); + nf.setFile( fileNm); + doc = new DocLnk(nf); + odebug << "Saving file as "+currentFileName << oendl; + doc->setName( fi.baseName() ); + updateCaption( currentFileName); + + FileManager fm; + if ( !fm.saveFile( *doc, rt ) ) { + QMessageBox::message(tr("Text Edit"),tr("Save Failed")); + return false; + } + + if( filePerms ) { + filePermissions *filePerm; + filePerm = new filePermissions(this, tr("Permissions"),true, 0, + (const QString &)fileNm); + QPEApplication::execDialog( filePerm ); + + delete filePerm; + } editor->setEdited( false); @@ -1199,6 +1179,4 @@ void TextEdit::doGoto() { - if(gotoEdit) { - delete gotoEdit; - gotoEdit = 0; - } + delete gotoEdit; + gotoEdit = 0; diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index 13f297e..61a47d7 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp @@ -237,3 +237,3 @@ void NotesControl::showMenu() { - if(m) delete m; + delete m; } diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 828f5a1..cf19ba8 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -498,3 +498,3 @@ void AdvancedFm::showFileMenu() { - if(m) delete m; + delete m; } |