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] 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(); }