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.
This commit is contained in:
Lukáš Hejl 2024-01-03 23:50:15 +01:00
parent c7d31f980a
commit 2c671d8d6c

View File

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