author | erik <erik> | 2007-01-26 20:22:50 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-26 20:22:50 (UTC) |
commit | 53d630c9c4813142ee13e6843c30476a5db26e78 (patch) (unidiff) | |
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 | |||
@@ -212,20 +212,26 @@ static void konsoleInit(const char** shell) { | |||
212 | // QPEApplication::grabKeyboard(); // for CTRL and ALT | 212 | // QPEApplication::grabKeyboard(); // for CTRL and ALT |
213 | 213 | ||
214 | odebug << "keyboard grabbed" << oendl; | 214 | odebug << "keyboard grabbed" << oendl; |
215 | #ifdef FAKE_CTRL_AND_ALT | 215 | #ifdef FAKE_CTRL_AND_ALT |
216 | odebug << "Fake Ctrl and Alt defined" << oendl; | 216 | odebug << "Fake Ctrl and Alt defined" << oendl; |
217 | QPEApplication::grabKeyboard(); // for CTRL and ALT | 217 | QPEApplication::grabKeyboard(); // for CTRL and ALT |
218 | #endif | 218 | #endif |
219 | 219 | ||
220 | if (!shell) { | ||
221 | owarn << "No double pointer 'shell'" << oendl; | ||
222 | return; | ||
223 | } | ||
224 | |||
220 | *shell = getenv("SHELL"); | 225 | *shell = getenv("SHELL"); |
221 | owarn << "SHell initially is " << *shell << "" << oendl; | 226 | if (*shell) |
227 | owarn << "Current shell: " << *shell << "" << oendl; | ||
222 | 228 | ||
223 | if (shell == NULL || *shell == '\0') { | 229 | if (*shell == NULL || **shell == '\0') { |
224 | struct passwd *ent = 0; | 230 | struct passwd *ent = 0; |
225 | uid_t me = getuid(); | 231 | uid_t me = getuid(); |
226 | *shell = "/bin/sh"; | 232 | *shell = "/bin/sh"; |
227 | 233 | ||
228 | while ( (ent = getpwent()) != 0 ) { | 234 | while ( (ent = getpwent()) != 0 ) { |
229 | if (ent->pw_uid == me) { | 235 | if (ent->pw_uid == me) { |
230 | if (ent->pw_shell != "") | 236 | if (ent->pw_shell != "") |
231 | *shell = ent->pw_shell; | 237 | *shell = ent->pw_shell; |
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 | |||
@@ -845,116 +845,96 @@ bool TextEdit::save() { | |||
845 | 845 | ||
846 | /*! | 846 | /*! |
847 | prompted save */ | 847 | prompted save */ |
848 | bool TextEdit::saveAs() { | 848 | bool TextEdit::saveAs() { |
849 | 849 | ||
850 | if(caption() == tr("Text Editor")) | 850 | if(caption() == tr("Text Editor")) |
851 | return false; | 851 | return false; |
852 | odebug << "saveAsFile " + currentFileName << oendl; | 852 | odebug << "saveAsFile " + currentFileName << oendl; |
853 | // case of nothing to save... | ||
854 | // if ( !doc && !currentFileName.isEmpty()) { | ||
855 | // //|| !bFromDocView) | ||
856 | // odebug << "no doc" << oendl; | ||
857 | // return true; | ||
858 | // } | ||
859 | // if ( !editor->edited() ) { | ||
860 | // delete doc; | ||
861 | // doc = 0; | ||
862 | // return true; | ||
863 | // } | ||
864 | 853 | ||
865 | QString rt = editor->text(); | 854 | QString rt = editor->text(); |
866 | odebug << currentFileName << oendl; | 855 | odebug << currentFileName << oendl; |
867 | 856 | ||
868 | if( currentFileName.isEmpty() | 857 | if( currentFileName.isEmpty() |
869 | || currentFileName == tr("Unnamed") | 858 | || currentFileName == tr("Unnamed") |
870 | || currentFileName == tr("Text Editor")) { | 859 | || currentFileName == tr("Text Editor")) |
860 | { | ||
871 | odebug << "do silly TT filename thing" << oendl; | 861 | odebug << "do silly TT filename thing" << oendl; |
872 | // if ( doc && doc->name().isEmpty() ) { | ||
873 | QString pt = rt.simplifyWhiteSpace(); | 862 | QString pt = rt.simplifyWhiteSpace(); |
874 | int i = pt.find( ' ' ); | 863 | int i = pt.find( ' ' ); |
875 | QString docname = pt; | 864 | QString docname = pt; |
876 | if ( i > 0 ) | 865 | if ( i > 0 ) docname = pt.left( i ); |
877 | docname = pt.left( i ); | 866 | |
878 | // remove "." at the beginning | ||
879 | while( docname.startsWith( "." ) ) | 867 | while( docname.startsWith( "." ) ) |
880 | docname = docname.mid( 1 ); | 868 | docname = docname.mid( 1 ); |
881 | docname.replace( QRegExp("/"), "_" ); | 869 | docname.replace( QRegExp("/"), "_" ); |
882 | // cut the length. filenames longer than that | 870 | // Cut the length. Filenames longer than 40 are not helpful |
883 | //don't make sense and something goes wrong when they get too long. | 871 | // and something goes wrong when they get too long. |
884 | if ( docname.length() > 40 ) | 872 | if ( docname.length() > 40 ) docname = docname.left(40); |
885 | docname = docname.left(40); | 873 | |
886 | if ( docname.isEmpty() ) | 874 | if ( docname.isEmpty() ) docname = tr("Unnamed"); |
887 | docname = tr("Unnamed"); | 875 | |
888 | if(doc) doc->setName(docname); | 876 | if(doc) doc->setName(docname); |
877 | |||
889 | currentFileName=docname; | 878 | currentFileName=docname; |
890 | // } | ||
891 | // else | ||
892 | // odebug << "hmmmmmm" << oendl; | ||
893 | } | 879 | } |
894 | 880 | ||
895 | 881 | ||
896 | QMap<QString, QStringList> map; | 882 | QMap<QString, QStringList> map; |
897 | map.insert(tr("All"), QStringList() ); | 883 | map.insert(tr("All"), QStringList() ); |
898 | QStringList text; | 884 | QStringList text; |
899 | text << "text/*"; | 885 | text << "text/*"; |
900 | map.insert(tr("Text"), text ); | 886 | map.insert(tr("Text"), text ); |
901 | text << "*"; | 887 | text << "*"; |
902 | map.insert(tr("All"), text ); | 888 | map.insert(tr("All"), text ); |
903 | 889 | ||
904 | QFileInfo cuFi( currentFileName); | 890 | QFileInfo cuFi( currentFileName); |
905 | QString filee = cuFi.fileName(); | 891 | QString filee = cuFi.fileName(); |
906 | QString dire = cuFi.dirPath(); | 892 | QString dire = cuFi.dirPath(); |
907 | if(dire==".") | 893 | if(dire==".") |
908 | dire = QPEApplication::documentDir(); | 894 | dire = QPEApplication::documentDir(); |
895 | |||
909 | QString str; | 896 | QString str; |
910 | if( !featureAutoSave) { | 897 | if( !featureAutoSave) { |
911 | str = OFileDialog::getSaveFileName( 2, | 898 | str = OFileDialog::getSaveFileName( 2, dire, filee, map); |
912 | dire, | 899 | } else |
913 | filee, map); | ||
914 | } else | ||
915 | str = currentFileName; | 900 | str = currentFileName; |
916 | 901 | ||
917 | if(!str.isEmpty()) { | 902 | if(!str.isEmpty()) { |
918 | QString fileNm=str; | 903 | QString fileNm=str; |
919 | 904 | ||
920 | odebug << "saving filename "+fileNm << oendl; | 905 | odebug << "saving filename "+fileNm << oendl; |
921 | QFileInfo fi(fileNm); | 906 | QFileInfo fi(fileNm); |
922 | currentFileName=fi.fileName(); | 907 | currentFileName=fi.fileName(); |
923 | if(doc) | 908 | if(doc) |
924 | // QString file = doc->file(); | ||
925 | // doc->removeFiles(); | ||
926 | delete doc; | 909 | delete doc; |
927 | DocLnk nf; | 910 | |
928 | nf.setType("text/plain"); | 911 | DocLnk nf; |
929 | nf.setFile( fileNm); | 912 | nf.setType("text/plain"); |
930 | doc = new DocLnk(nf); | 913 | nf.setFile( fileNm); |
931 | // editor->setText(rt); | 914 | doc = new DocLnk(nf); |
932 | odebug << "Saving file as "+currentFileName << oendl; | 915 | odebug << "Saving file as "+currentFileName << oendl; |
933 | doc->setName( fi.baseName() /*currentFileName*/); | 916 | doc->setName( fi.baseName() ); |
934 | updateCaption( currentFileName); | 917 | updateCaption( currentFileName); |
935 | 918 | ||
936 | FileManager fm; | 919 | FileManager fm; |
937 | if ( !fm.saveFile( *doc, rt ) ) { | 920 | if ( !fm.saveFile( *doc, rt ) ) { |
938 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 921 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
939 | return false; | 922 | return false; |
940 | } | 923 | } |
941 | 924 | ||
942 | if( filePerms ) { | 925 | if( filePerms ) { |
943 | filePermissions *filePerm; | 926 | filePermissions *filePerm; |
944 | filePerm = new filePermissions(this, | 927 | filePerm = new filePermissions(this, tr("Permissions"),true, 0, |
945 | tr("Permissions"),true, | 928 | (const QString &)fileNm); |
946 | 0,(const QString &)fileNm); | 929 | QPEApplication::execDialog( filePerm ); |
947 | QPEApplication::execDialog( filePerm ); | 930 | |
948 | 931 | delete filePerm; | |
949 | if( filePerm) | 932 | } |
950 | delete filePerm; | ||
951 | } | ||
952 | // } | ||
953 | editor->setEdited( false); | 933 | editor->setEdited( false); |
954 | edited1 = false; | 934 | edited1 = false; |
955 | edited = false; | 935 | edited = false; |
956 | if(caption().left(1)=="*") | 936 | if(caption().left(1)=="*") |
957 | setCaption(caption().right(caption().length()-1)); | 937 | setCaption(caption().right(caption().length()-1)); |
958 | 938 | ||
959 | return true; | 939 | return true; |
960 | } | 940 | } |
@@ -1192,20 +1172,18 @@ void TextEdit::gotoLine() { | |||
1192 | gotoEdit->show(); | 1172 | gotoEdit->show(); |
1193 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | 1173 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); |
1194 | } | 1174 | } |
1195 | 1175 | ||
1196 | void TextEdit::doGoto() { | 1176 | void TextEdit::doGoto() { |
1197 | QString number = gotoEdit->text(); | 1177 | QString number = gotoEdit->text(); |
1198 | gotoEdit->hide(); | 1178 | gotoEdit->hide(); |
1199 | 1179 | ||
1200 | if(gotoEdit) { | 1180 | delete gotoEdit; |
1201 | delete gotoEdit; | 1181 | gotoEdit = 0; |
1202 | gotoEdit = 0; | ||
1203 | } | ||
1204 | 1182 | ||
1205 | bool ok; | 1183 | bool ok; |
1206 | int lineNumber = number.toInt(&ok, 10); | 1184 | int lineNumber = number.toInt(&ok, 10); |
1207 | if( editor->numLines() < lineNumber) | 1185 | if( editor->numLines() < lineNumber) |
1208 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | 1186 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); |
1209 | else | 1187 | else |
1210 | { | 1188 | { |
1211 | editor->setCursorPosition(lineNumber, 0, false); | 1189 | editor->setCursorPosition(lineNumber, 0, false); |
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 | |||
@@ -230,17 +230,17 @@ void NotesControl::showMenu() { | |||
230 | m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); | 230 | m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); |
231 | m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); | 231 | m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); |
232 | m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); | 232 | m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); |
233 | m->insertSeparator(); | 233 | m->insertSeparator(); |
234 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); | 234 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); |
235 | m->setFocus(); | 235 | m->setFocus(); |
236 | m->exec( QCursor::pos() ); | 236 | m->exec( QCursor::pos() ); |
237 | 237 | ||
238 | if(m) delete m; | 238 | delete m; |
239 | } | 239 | } |
240 | 240 | ||
241 | void NotesControl::focusOutEvent ( QFocusEvent * e) { | 241 | void NotesControl::focusOutEvent ( QFocusEvent * e) { |
242 | if( e->reason() == QFocusEvent::Popup) | 242 | if( e->reason() == QFocusEvent::Popup) |
243 | save(); | 243 | save(); |
244 | else { | 244 | else { |
245 | if(!loaded) { | 245 | if(!loaded) { |
246 | populateBox(); | 246 | populateBox(); |
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 | |||
@@ -491,17 +491,17 @@ void AdvancedFm::showFileMenu() { | |||
491 | m->setItemChecked(m->idAt(0),FALSE); | 491 | m->setItemChecked(m->idAt(0),FALSE); |
492 | 492 | ||
493 | if(Ir::supported()) | 493 | if(Ir::supported()) |
494 | m->insertItem(tr("Beam File"),this,SLOT(doBeam())); | 494 | m->insertItem(tr("Beam File"),this,SLOT(doBeam())); |
495 | m->setFocus(); | 495 | m->setFocus(); |
496 | 496 | ||
497 | m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y())); | 497 | m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y())); |
498 | 498 | ||
499 | if(m) delete m; | 499 | delete m; |
500 | } | 500 | } |
501 | 501 | ||
502 | 502 | ||
503 | QString AdvancedFm::checkDiskSpace(const QString &path) { | 503 | QString AdvancedFm::checkDiskSpace(const QString &path) { |
504 | struct statfs fss; | 504 | struct statfs fss; |
505 | if ( !statfs( path.latin1(), &fss ) ) { | 505 | if ( !statfs( path.latin1(), &fss ) ) { |
506 | int blkSize = fss.f_bsize; | 506 | int blkSize = fss.f_bsize; |
507 | // int totalBlks = fs.f_blocks; | 507 | // int totalBlks = fs.f_blocks; |