From 2c671d8d6cf70a0794bbc2e25d48e1f191753f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Wed, 3 Jan 2024 23:50:15 +0100 Subject: [PATCH 1/6] Use memcpy instead of strncpy in GCodeFormatter::emit_string() to silence the warning. The warning was there because std::string_view::data() returns a pointer to a buffer that is not necessarily null-terminated. So, strncpy shouldn't be used on non-null-terminated buffers, but we always relied only on the buffer length, so it couldn't cause any issues. --- src/libslic3r/GCode/GCodeWriter.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/GCodeWriter.hpp b/src/libslic3r/GCode/GCodeWriter.hpp index b51b6269c5..d91e67728d 100644 --- a/src/libslic3r/GCode/GCodeWriter.hpp +++ b/src/libslic3r/GCode/GCodeWriter.hpp @@ -200,7 +200,8 @@ public: } void emit_string(const std::string_view s) { - strncpy(ptr_err.ptr, s.data(), s.size()); + // Be aware that std::string_view::data() returns a pointer to a buffer that is not necessarily null-terminated. + memcpy(ptr_err.ptr, s.data(), s.size()); ptr_err.ptr += s.size(); } From 611afd97895a092bc226c11b373b1451cf0f4171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Wed, 3 Jan 2024 23:55:02 +0100 Subject: [PATCH 2/6] Replace some deprecated boost functions. Actually, all those deprecated functions were internally called those new functions. So there isn't any risk to use them directly. --- src/libslic3r/PrintBase.cpp | 2 +- src/libslic3r/utils.cpp | 2 +- src/slic3r/GUI/DownloaderFileGet.cpp | 2 +- src/slic3r/GUI/GalleryDialog.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 6 +++--- src/slic3r/GUI/RemovableDriveManager.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/PrintBase.cpp b/src/libslic3r/PrintBase.cpp index 18d9833974..ca13365d15 100644 --- a/src/libslic3r/PrintBase.cpp +++ b/src/libslic3r/PrintBase.cpp @@ -78,7 +78,7 @@ std::string PrintBase::output_filename(const std::string &format, const std::str cfg.opt_string("input_filename_base") + default_ext : this->placeholder_parser().process(format, 0, &cfg); if (filename.extension().empty()) - filename = boost::filesystem::change_extension(filename, default_ext); + filename.replace_extension(default_ext); return filename.string(); } catch (std::runtime_error &err) { throw Slic3r::PlaceholderParserError(_u8L("Failed processing of the output_filename_format template.") + "\n" + err.what()); diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 09fa98ca1f..f4d7c51da1 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -707,7 +707,7 @@ CopyFileResult copy_file_inner(const std::string& from, const std::string& to, s // That may happen when copying on some exotic file system, for example Linux on Chrome. copy_file_linux(source, target, ec); #else // __linux__ - boost::filesystem::copy_file(source, target, boost::filesystem::copy_option::overwrite_if_exists, ec); + boost::filesystem::copy_file(source, target, boost::filesystem::copy_options::overwrite_existing, ec); #endif // __linux__ if (ec) { error_message = ec.message(); diff --git a/src/slic3r/GUI/DownloaderFileGet.cpp b/src/slic3r/GUI/DownloaderFileGet.cpp index 137a7e9bc1..ef9b0256e0 100644 --- a/src/slic3r/GUI/DownloaderFileGet.cpp +++ b/src/slic3r/GUI/DownloaderFileGet.cpp @@ -138,7 +138,7 @@ void FileGet::priv::get_perform() if (m_written == 0) { boost::filesystem::path dest_path = m_dest_folder / m_filename; - std::string extension = boost::filesystem::extension(dest_path); + std::string extension = dest_path.extension().string(); std::string just_filename = m_filename.substr(0, m_filename.size() - extension.size()); std::string final_filename = just_filename; // Find unsed filename diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index cb4e6764c9..23c2cc8e08 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -503,7 +503,7 @@ void GalleryDialog::change_thumbnail() png_path.replace_extension("png"); fs::path current = fs::path(into_u8(input_files.Item(0))); - fs::copy_file(current, png_path, fs::copy_option::overwrite_if_exists); + fs::copy_file(current, png_path, fs::copy_options::overwrite_existing); } catch (fs::filesystem_error const& e) { std::cerr << e.what() << '\n'; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 2642bcc450..ab98771f64 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5633,7 +5633,7 @@ void Plater::convert_gcode_to_ascii() if (res == EResult::InvalidMagicNumber) { in_file.close(); out_file.close(); - boost::filesystem::copy_file(input_path, output_path, boost::filesystem::copy_option::overwrite_if_exists); + boost::filesystem::copy_file(input_path, output_path, boost::filesystem::copy_options::overwrite_existing); } else if (res != EResult::Success) { MessageDialog msg_dlg(this, _L(std::string(translate_result(res))), _L("Error converting G-code file"), wxICON_INFORMATION | wxOK); @@ -5712,7 +5712,7 @@ void Plater::convert_gcode_to_binary() if (res == EResult::AlreadyBinarized) { in_file.close(); out_file.close(); - boost::filesystem::copy_file(input_path, output_path, boost::filesystem::copy_option::overwrite_if_exists); + boost::filesystem::copy_file(input_path, output_path, boost::filesystem::copy_options::overwrite_existing); } else if (res != EResult::Success) { MessageDialog msg_dlg(this, _L(std::string(translate_result(res))), _L("Error converting G-code file"), wxICON_INFORMATION | wxOK); @@ -5945,7 +5945,7 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) std::replace(name.begin(), name.end(), '\\', '/'); // rename if file exists std::string filename = path.filename().string(); - std::string extension = boost::filesystem::extension(path); + std::string extension = path.extension().string(); std::string just_filename = filename.substr(0, filename.size() - extension.size()); std::string final_filename = just_filename; diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 52ae1dad8b..399ea8180d 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -759,7 +759,7 @@ namespace search_for_drives_internal stat(path.c_str(), &buf); uid_t uid = buf.st_uid; if (getuid() == uid) - out.emplace_back(DriveData{ boost::filesystem::basename(boost::filesystem::path(path)), path }); + out.emplace_back(DriveData{ boost::filesystem::path(path).stem().string(), path }); } } } From a27aea45989c2a26038b0d84fd51bf7d6104166f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Wed, 3 Jan 2024 23:57:51 +0100 Subject: [PATCH 3/6] Remove the unused variable new_radius in Arc Welder tests. --- tests/libslic3r/test_arc_welder.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/libslic3r/test_arc_welder.cpp b/tests/libslic3r/test_arc_welder.cpp index 44b88655ea..f0ab8fbab3 100644 --- a/tests/libslic3r/test_arc_welder.cpp +++ b/tests/libslic3r/test_arc_welder.cpp @@ -280,7 +280,6 @@ TEST_CASE("least squares arc fitting, interpolating end points", "[ArcWelder]") REQUIRE(new_center_opt); if (new_center_opt) { Vec2d new_center = *new_center_opt; - double new_radius = (new_center - start_pos).norm(); double total_deviation = 0; double new_total_deviation = 0; for (const Vec2d &s : samples) { From da88c2affcda5b79320e1ab0389f6056a535da39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Thu, 4 Jan 2024 00:09:49 +0100 Subject: [PATCH 4/6] Silence the warning about the unused total_extrusion_length in Arachne tests. --- tests/libslic3r/test_arachne.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/libslic3r/test_arachne.cpp b/tests/libslic3r/test_arachne.cpp index c5b2f35a9b..2953cfcfab 100644 --- a/tests/libslic3r/test_arachne.cpp +++ b/tests/libslic3r/test_arachne.cpp @@ -478,7 +478,7 @@ TEST_CASE("Arachne - #8849 - Missing part of model", "[ArachneMissingPart8849]") export_perimeters_to_svg(debug_out_path("arachne-missing-part-8849.svg"), polygons, perimeters, union_ex(wall_tool_paths.getInnerContour())); #endif - int64_t total_extrusion_length = 0; + [[maybe_unused]] int64_t total_extrusion_length = 0; for (Arachne::VariableWidthLines &perimeter : perimeters) for (Arachne::ExtrusionLine &extrusion_line : perimeter) total_extrusion_length += extrusion_line.getLength(); From 124ce1c31fb24ce05191971997d985e56ac69daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Thu, 4 Jan 2024 00:10:20 +0100 Subject: [PATCH 5/6] Silence the warning about the unused function get_deviation_sum_squared() in Arc Welder. --- src/libslic3r/Geometry/ArcWelder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libslic3r/Geometry/ArcWelder.cpp b/src/libslic3r/Geometry/ArcWelder.cpp index 4b02a31dce..0bc71aea3a 100644 --- a/src/libslic3r/Geometry/ArcWelder.cpp +++ b/src/libslic3r/Geometry/ArcWelder.cpp @@ -120,6 +120,7 @@ static inline bool circle_approximation_sufficient(const Circle &circle, const P return true; } +#if 0 static inline bool get_deviation_sum_squared(const Circle &circle, const Points::const_iterator begin, const Points::const_iterator end, const double tolerance, double &total_deviation) { // The circle was calculated from the 1st and last point of the point sequence, thus the fitting of those points does not need to be evaluated. @@ -148,6 +149,7 @@ static inline bool get_deviation_sum_squared(const Circle &circle, const Points: return true; } +#endif double arc_fit_variance(const Point &start_pos, const Point &end_pos, const float radius, bool is_ccw, const Points::const_iterator begin, const Points::const_iterator end) From ca811aaa7d0beecd2e0bd5c58b3794febb2f07c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Thu, 4 Jan 2024 00:11:03 +0100 Subject: [PATCH 6/6] Move the function ptree_get_value() inside _WIN32 ifdef. --- src/slic3r/Utils/WifiScanner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/Utils/WifiScanner.cpp b/src/slic3r/Utils/WifiScanner.cpp index 260583516d..aa4c8f4e9f 100644 --- a/src/slic3r/Utils/WifiScanner.cpp +++ b/src/slic3r/Utils/WifiScanner.cpp @@ -24,6 +24,8 @@ #endif //__linux__ namespace { + +#ifdef _WIN32 bool ptree_get_value(const boost::property_tree::ptree& pt, const std::string& target, std::string& result) { // Check if the current node has the target element @@ -41,7 +43,7 @@ bool ptree_get_value(const boost::property_tree::ptree& pt, const std::string& t return false; // Element not found in this subtree } -#ifdef _WIN32 + // Fill SSID map. Implementation from Raspberry Pi imager and Win32 Api examples. // https://github.com/raspberrypi/rpi-imager/blob/qml/src/windows/winwlancredentials.cpp // https://learn.microsoft.com/en-us/windows/win32/api/wlanapi/nf-wlanapi-wlangetavailablenetworklist