From 7a0017561fb7f75cd8fd0cc97dbdba5d6c0aed75 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Tue, 7 Dec 2021 23:11:19 -0500 Subject: [PATCH 1/2] Use zeroes instead of random data for dummy file --- src/applications/gqrx/file_resources.cpp | 6 +++--- src/applications/gqrx/receiver.cpp | 4 ++-- src/applications/gqrx/receiver.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/applications/gqrx/file_resources.cpp b/src/applications/gqrx/file_resources.cpp index d7f75c5b8..8d751827a 100644 --- a/src/applications/gqrx/file_resources.cpp +++ b/src/applications/gqrx/file_resources.cpp @@ -27,12 +27,12 @@ #include #include -std::string receiver::get_random_file(void) +std::string receiver::get_zero_file(void) { static std::string path; if (path.empty()) { - path = "/dev/urandom"; + path = "/dev/zero"; QFileInfo checkFile(QString::fromStdString(path)); if (!checkFile.exists()) { @@ -42,7 +42,7 @@ std::string receiver::get_random_file(void) path = temp_file.fileName().toStdString(); { QDataStream stream(&temp_file); - for (size_t i = 0; i < 1024*8; i++) stream << qint8(rand()); + for (size_t i = 0; i < 1024*8; i++) stream << qint8(0); } temp_file.close(); std::cout << "Created random file " << path << std::endl; diff --git a/src/applications/gqrx/receiver.cpp b/src/applications/gqrx/receiver.cpp index fd6e44a0e..c6b280a99 100644 --- a/src/applications/gqrx/receiver.cpp +++ b/src/applications/gqrx/receiver.cpp @@ -76,7 +76,7 @@ receiver::receiver(const std::string input_device, if (input_device.empty()) { - src = osmosdr::source::make("file="+get_random_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); + src = osmosdr::source::make("file="+get_zero_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); } else { @@ -215,7 +215,7 @@ void receiver::set_input_device(const std::string device) catch (std::exception &x) { error = x.what(); - src = osmosdr::source::make("file="+get_random_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); + src = osmosdr::source::make("file="+get_zero_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); } if(src->get_sample_rate() != 0) diff --git a/src/applications/gqrx/receiver.h b/src/applications/gqrx/receiver.h index a9e15d2bc..4873882a8 100644 --- a/src/applications/gqrx/receiver.h +++ b/src/applications/gqrx/receiver.h @@ -292,7 +292,7 @@ class receiver #endif //! Get a path to a file containing random bytes - static std::string get_random_file(void); + static std::string get_zero_file(void); }; #endif // RECEIVER_H From 2c6dfba90eeac27394390af204664d8021f82853 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Tue, 7 Dec 2021 23:31:01 -0500 Subject: [PATCH 2/2] Escape filename in device specification string --- resources/news.txt | 2 ++ src/CMakeLists.txt | 2 +- src/applications/gqrx/mainwindow.cpp | 5 +++-- src/applications/gqrx/receiver.cpp | 16 ++++++++++++++-- src/applications/gqrx/receiver.h | 3 +++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/resources/news.txt b/resources/news.txt index 8399b9184..e3b2de016 100644 --- a/resources/news.txt +++ b/resources/news.txt @@ -5,6 +5,8 @@ NEW: Added IQ balancing to MacOS release. FIXED: Erratic behaviour of S-meter. FIXED: Compilation error due to missing include. + FIXED: Startup crash on Windows. + FIXED: I/Q playback when filename contains special characters. IMPROVED: Reordered the receiver mode drop-down list. IMPROVED: Receiver mode is now stored as a string in settings files. IMPROVED: Increased automatic squelch margin to 3 dB. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e05f2474..ef1ede131 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,7 +57,7 @@ endif(WIN32) ####################################################################################################################### # Build the program add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE} ${UIS_HDRS} ${RESOURCES_LIST}) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) # The pulse libraries are only needed on Linux. On other platforms they will not be found, so having them here is fine. target_link_libraries(${PROJECT_NAME} Qt5::Core diff --git a/src/applications/gqrx/mainwindow.cpp b/src/applications/gqrx/mainwindow.cpp index 802d72888..4d657b86d 100644 --- a/src/applications/gqrx/mainwindow.cpp +++ b/src/applications/gqrx/mainwindow.cpp @@ -1599,8 +1599,9 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate) storeSession(); auto sri = (int)samprate; - auto devstr = QString("file='%1',rate=%2,throttle=true,repeat=false") - .arg(filename).arg(sri); + QString escapedFilename = receiver::escape_filename(filename.toStdString()).c_str(); + auto devstr = QString("file=%1,rate=%2,throttle=true,repeat=false") + .arg(escapedFilename).arg(sri); qDebug() << __func__ << ":" << devstr; diff --git a/src/applications/gqrx/receiver.cpp b/src/applications/gqrx/receiver.cpp index c6b280a99..b80f08c45 100644 --- a/src/applications/gqrx/receiver.cpp +++ b/src/applications/gqrx/receiver.cpp @@ -21,7 +21,9 @@ * Boston, MA 02110-1301, USA. */ #include +#include #include +#include #include #include @@ -76,7 +78,7 @@ receiver::receiver(const std::string input_device, if (input_device.empty()) { - src = osmosdr::source::make("file="+get_zero_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); + src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true"); } else { @@ -215,7 +217,7 @@ void receiver::set_input_device(const std::string device) catch (std::exception &x) { error = x.what(); - src = osmosdr::source::make("file="+get_zero_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); + src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true"); } if(src->get_sample_rate() != 0) @@ -1413,3 +1415,13 @@ void receiver::reset_rds_parser(void) { rx->reset_rds_parser(); } + +std::string receiver::escape_filename(std::string filename) +{ + std::stringstream ss1; + std::stringstream ss2; + + ss1 << std::quoted(filename, '\'', '\\'); + ss2 << std::quoted(ss1.str(), '\'', '\\'); + return ss2.str(); +} diff --git a/src/applications/gqrx/receiver.h b/src/applications/gqrx/receiver.h index 4873882a8..abf827cb8 100644 --- a/src/applications/gqrx/receiver.h +++ b/src/applications/gqrx/receiver.h @@ -229,6 +229,9 @@ class receiver bool is_rds_decoder_active(void) const; void reset_rds_parser(void); + /* utility functions */ + static std::string escape_filename(std::string filename); + private: void connect_all(rx_chain type);