diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp
index f145fcec6..5722d0ad7 100644
--- a/src/libslic3r/GCode/GCodeProcessor.cpp
+++ b/src/libslic3r/GCode/GCodeProcessor.cpp
@@ -977,7 +977,9 @@ template<typename T>
     {
         // Legacy conversion, which is costly due to having to make a copy of the string before conversion.
         try {
-            std::string str { str };
+            assert(sv.size() < 1024);
+	    assert(sv.data() != nullptr);
+            std::string str { sv };
             size_t read = 0;
             if constexpr (std::is_same_v<T, int>)
                 out = std::stoi(str, &read);