From 08fa362abdec8c7c89c0c7253efe68d9662255ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Mon, 4 Mar 2024 18:15:32 +0100 Subject: [PATCH] Fix undefined behaviour in maybe change instance --- src/libslic3r/GCode/LabelObjects.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/LabelObjects.cpp b/src/libslic3r/GCode/LabelObjects.cpp index dee3759417..a3409819e7 100644 --- a/src/libslic3r/GCode/LabelObjects.cpp +++ b/src/libslic3r/GCode/LabelObjects.cpp @@ -138,7 +138,10 @@ std::string LabelObjects::maybe_stop_instance() { std::string LabelObjects::maybe_change_instance() { if (last_operation_instance != current_instance) { - return this->maybe_stop_instance() + this->maybe_start_instance(); + const std::string stop_instance_gcode{this->maybe_stop_instance()}; + // Be carefull with refactoring: this->maybe_stop_instance() + this->maybe_start_instance() + // may not be evaluated in order. The order is indeed undefined! + return stop_instance_gcode + this->maybe_start_instance(); } return ""; }