From 0cd2935b8ca4d277400041122c1a700d83a8aec4 Mon Sep 17 00:00:00 2001 From: Uwe Risse Date: Tue, 1 Nov 2022 16:40:08 +0100 Subject: [PATCH] Prevent some possible segfault errors (patch by Mike W9MDB). --- Transceiver/DXLabSuiteCommanderTransceiver.cpp | 4 ++++ widgets/mainwindow.cpp | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Transceiver/DXLabSuiteCommanderTransceiver.cpp b/Transceiver/DXLabSuiteCommanderTransceiver.cpp index 2014c1044..a96480662 100644 --- a/Transceiver/DXLabSuiteCommanderTransceiver.cpp +++ b/Transceiver/DXLabSuiteCommanderTransceiver.cpp @@ -444,8 +444,12 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd) // qDebug () << i << ":" << hex << int (result[i]); // } + if (result != NULL) + { CAT_TRACE (cmd << " -> " << QString {result}); return result; // converting raw UTF-8 bytes to QString + } + return ""; } bool DXLabSuiteCommanderTransceiver::write_to_port (QString const& s) diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 43e9c7f2d..d78e2f857 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -90,6 +90,7 @@ #include "ExportCabrillo.h" #include "ui_mainwindow.h" #include "moc_mainwindow.cpp" +#include "Logger.hpp" #define FCL fortran_charlen_t @@ -1385,7 +1386,9 @@ void MainWindow::set_application_font (QFont const& font) QFile sf {sheet}; if (sf.open (QFile::ReadOnly | QFile::Text)) { - ss = sf.readAll () + ss; + QString tmp = sf.readAll(); + if (tmp != NULL) ss = sf.readAll () + tmp; + else qDebug() << "tmp==NULL at sf.readAll"; } } qApp->setStyleSheet (ss + "* {" + font_as_stylesheet (font) + '}'); @@ -4023,7 +4026,8 @@ void MainWindow::readFromStdout() //readFromStdout if(f.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream s(&f); QString t=s.readAll(); - m_msgAvgWidget->displayAvg(t); + if (t != NULL) m_msgAvgWidget->displayAvg(t); + else qDebug() << "tmp==NULL at s.readAll"; } } } @@ -6152,7 +6156,9 @@ void MainWindow::on_addButton_clicked() //Add button // preserve symlinks f1.open (QFile::WriteOnly | QFile::Text); // truncates f2.seek (0); - f1.write (f2.readAll ()); // copy contents + QByteArray tmp = f2.readAll(); + if (tmp != (const char*)NULL) f1.write (tmp); // copy contents + else qDebug() << "tmp==NULL at f1.write"; f2.remove (); } }