From 90a539ed26e91714a39b990a6f03b588c5a98a03 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 13 Jul 2019 14:28:48 +0200 Subject: [PATCH] Avoid using cstdio header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See MISRA C++:2008, 27-0-1 - The stream input/output library  shall not be used. Replaced by filesystem library. Avoid using cstring when it is easily replaced --- src/algorithms/PVT/libs/geojson_printer.cc | 4 +- src/algorithms/PVT/libs/gpx_printer.cc | 4 +- src/algorithms/PVT/libs/kml_printer.cc | 5 +- src/algorithms/PVT/libs/nmea_printer.cc | 9 +++ src/algorithms/PVT/libs/rinex_printer.cc | 71 ++++++++++--------- src/algorithms/PVT/libs/rtcm_printer.cc | 4 +- src/algorithms/tracking/libs/dll_pll_conf.cc | 6 +- .../tracking/libs/dll_pll_conf_fpga.cc | 6 +- 8 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/algorithms/PVT/libs/geojson_printer.cc b/src/algorithms/PVT/libs/geojson_printer.cc index f15d9efef..a88ae7dcf 100644 --- a/src/algorithms/PVT/libs/geojson_printer.cc +++ b/src/algorithms/PVT/libs/geojson_printer.cc @@ -34,7 +34,6 @@ #include "pvt_solution.h" #include #include -#include // for remove #include // for tm #include // for exception #include // for operator<< @@ -240,7 +239,8 @@ bool GeoJSON_Printer::close_file() // if nothing is written, erase the file if (first_pos == true) { - if (remove(filename_.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(filename_), ec)) { LOG(INFO) << "Error deleting temporary file"; } diff --git a/src/algorithms/PVT/libs/gpx_printer.cc b/src/algorithms/PVT/libs/gpx_printer.cc index 0cc7ded4b..ee6caded1 100644 --- a/src/algorithms/PVT/libs/gpx_printer.cc +++ b/src/algorithms/PVT/libs/gpx_printer.cc @@ -34,7 +34,6 @@ #include "rtklib_solver.h" #include #include -#include // for remove #include // for tm #include // for exception #include // for operator<< @@ -251,7 +250,8 @@ Gpx_Printer::~Gpx_Printer() } if (!positions_printed) { - if (remove(gpx_filename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(gpx_filename), ec)) { LOG(INFO) << "Error deleting temporary GPX file"; } diff --git a/src/algorithms/PVT/libs/kml_printer.cc b/src/algorithms/PVT/libs/kml_printer.cc index f726531e0..d5ddedb49 100644 --- a/src/algorithms/PVT/libs/kml_printer.cc +++ b/src/algorithms/PVT/libs/kml_printer.cc @@ -34,9 +34,7 @@ #include "rtklib_solver.h" #include #include -#include // for remove #include // for mkstemp -#include // for strncpy #include // for tm #include // for exception #include // for cout, cerr @@ -366,7 +364,8 @@ Kml_Printer::~Kml_Printer() } if (!positions_printed) { - if (remove(kml_filename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(kml_filename), ec)) { LOG(INFO) << "Error deleting temporary KML file"; } diff --git a/src/algorithms/PVT/libs/nmea_printer.cc b/src/algorithms/PVT/libs/nmea_printer.cc index 913a23e39..4a85a6214 100644 --- a/src/algorithms/PVT/libs/nmea_printer.cc +++ b/src/algorithms/PVT/libs/nmea_printer.cc @@ -133,6 +133,7 @@ Nmea_Printer::Nmea_Printer(const std::string& filename, bool flag_nmea_output_fi Nmea_Printer::~Nmea_Printer() { + auto pos = nmea_file_descriptor.tellp(); try { if (nmea_file_descriptor.is_open()) @@ -148,6 +149,14 @@ Nmea_Printer::~Nmea_Printer() { std::cerr << e.what() << '\n'; } + if (pos == 0) + { + errorlib::error_code ec; + if (!fs::remove(fs::path(nmea_filename), ec)) + { + std::cerr << "Problem removing NMEA temporary file: " << nmea_filename << '\n'; + } + } try { close_serial(); diff --git a/src/algorithms/PVT/libs/rinex_printer.cc b/src/algorithms/PVT/libs/rinex_printer.cc index 7b6f14ee6..8217e2bdc 100644 --- a/src/algorithms/PVT/libs/rinex_printer.cc +++ b/src/algorithms/PVT/libs/rinex_printer.cc @@ -56,7 +56,6 @@ #include #include // for min and max #include // for floor -#include // for memcpy #include #include // for cout #include @@ -267,51 +266,59 @@ Rinex_Printer::~Rinex_Printer() std::cerr << e.what() << '\n'; } // If nothing written, erase the files. + if (posn == 0) { - if (remove(navfilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(navfilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } } if (poso == 0) { - if (remove(obsfilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(obsfilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } } if (poss == 0) { - if (remove(sbsfilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(sbsfilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } } if (posng == 0) { - if (remove(navGalfilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(navGalfilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } } if (posmn == 0) { - if (remove(navMixfilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(navMixfilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } } if (posnr == 0) { - if (remove(navGlofilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(navGlofilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } } if (posnc == 0) { - if (remove(navBdsfilename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(navBdsfilename), ec)) { LOG(INFO) << "Error deleting temporary file"; } @@ -10171,10 +10178,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Gps_Ephemeris& eph, c if ((total_mmap.count(mmap_iter->second.PRN)) == 1 && (mmap_iter->second.PRN != 0)) { Gnss_Synchro gs = Gnss_Synchro(); - std::string sys = "G"; - gs.System = *sys.c_str(); - std::string sig = "2S"; - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = 'G'; + gs.Signal[0] = '2'; + gs.Signal[1] = 'S'; + gs.Signal[2] = '\0'; gs.PRN = mmap_iter->second.PRN; total_mmap.insert(std::pair(mmap_iter->second.PRN, gs)); } @@ -10401,10 +10408,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& ep if (found_1B != std::string::npos) { Gnss_Synchro gs = Gnss_Synchro(); - std::string sys = "E"; - gs.System = *sys.c_str(); - std::string sig = "1B"; - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = 'E'; + gs.Signal[0] = '1'; + gs.Signal[1] = 'B'; + gs.Signal[2] = '\0'; gs.PRN = prn_; total_map.insert(std::pair(prn_, gs)); } @@ -10426,20 +10433,20 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& ep if (found_1B != std::string::npos) { Gnss_Synchro gs = Gnss_Synchro(); - std::string sys = "E"; - gs.System = *sys.c_str(); - std::string sig = "1B"; - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = 'E'; + gs.Signal[0] = '1'; + gs.Signal[1] = 'B'; + gs.Signal[2] = '\0'; gs.PRN = prn_; total_map.insert(std::pair(prn_, gs)); } if (found_E5a != std::string::npos) { Gnss_Synchro gs = Gnss_Synchro(); - std::string sys = "E"; - gs.System = *sys.c_str(); - std::string sig = "5X"; - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = 'E'; + gs.Signal[0] = '5'; + gs.Signal[1] = 'X'; + gs.Signal[2] = '\0'; gs.PRN = prn_; total_map.insert(std::pair(prn_, gs)); } @@ -10452,10 +10459,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& ep if ((total_map.count(prn_)) == 1) { Gnss_Synchro gs = Gnss_Synchro(); - std::string sys = "E"; - gs.System = *sys.c_str(); - std::string sig = "5X"; - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = 'E'; + gs.Signal[0] = '5'; + gs.Signal[1] = 'X'; + gs.Signal[2] = '\0'; gs.PRN = prn_; total_map.insert(std::pair(prn_, gs)); } @@ -11521,10 +11528,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Beidou_Dnav_Ephemeris if (found_B1 != std::string::npos) { Gnss_Synchro gs = Gnss_Synchro(); - std::string sys = "C"; - gs.System = *sys.c_str(); - std::string sig = "B1"; - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = 'C'; + gs.Signal[0] = 'B'; + gs.Signal[1] = '1'; + gs.Signal[2] = '\0'; gs.PRN = prn_; total_map.insert(std::pair(prn_, gs)); } diff --git a/src/algorithms/PVT/libs/rtcm_printer.cc b/src/algorithms/PVT/libs/rtcm_printer.cc index 1ced95bfc..d30959017 100644 --- a/src/algorithms/PVT/libs/rtcm_printer.cc +++ b/src/algorithms/PVT/libs/rtcm_printer.cc @@ -40,7 +40,6 @@ #include "gps_ephemeris.h" #include "rtcm.h" #include -#include // for remove #include // for tm #include // for exception #include // for O_RDWR @@ -221,7 +220,8 @@ Rtcm_Printer::~Rtcm_Printer() } if (pos == 0) { - if (remove(rtcm_filename.c_str()) != 0) + errorlib::error_code ec; + if (!fs::remove(fs::path(rtcm_filename), ec)) { LOG(INFO) << "Error deleting temporary RTCM file"; } diff --git a/src/algorithms/tracking/libs/dll_pll_conf.cc b/src/algorithms/tracking/libs/dll_pll_conf.cc index 81ecb99b6..fa0705ffe 100644 --- a/src/algorithms/tracking/libs/dll_pll_conf.cc +++ b/src/algorithms/tracking/libs/dll_pll_conf.cc @@ -32,7 +32,6 @@ #include "dll_pll_conf.h" #include "gnss_sdr_flags.h" -#include Dll_Pll_Conf::Dll_Pll_Conf() { @@ -72,6 +71,7 @@ Dll_Pll_Conf::Dll_Pll_Conf() enable_doppler_correction = false; track_pilot = false; system = 'G'; - char sig_[3] = "1C"; - std::memcpy(signal, sig_, 3); + signal[0] = '1'; + signal[1] = 'C'; + signal[2] = '\0'; } diff --git a/src/algorithms/tracking/libs/dll_pll_conf_fpga.cc b/src/algorithms/tracking/libs/dll_pll_conf_fpga.cc index 8ad8f3a13..9c4447cf5 100644 --- a/src/algorithms/tracking/libs/dll_pll_conf_fpga.cc +++ b/src/algorithms/tracking/libs/dll_pll_conf_fpga.cc @@ -32,7 +32,6 @@ #include "dll_pll_conf_fpga.h" -#include Dll_Pll_Conf_Fpga::Dll_Pll_Conf_Fpga() { @@ -68,8 +67,9 @@ Dll_Pll_Conf_Fpga::Dll_Pll_Conf_Fpga() carrier_lock_th = 0.85; track_pilot = false; system = 'G'; - char sig_[3] = "1C"; - std::memcpy(signal, sig_, 3); + signal[0] = '1'; + signal[1] = 'C'; + signal[2] = '\0'; device_name = "/dev/uio"; device_base = 1U; multicorr_type = 0U;