Browse Source

Fix process_injected_command undefined behavior (#14602)

Marcio Teixeira 6 years ago
parent
commit
cbe4bf2ba8
1 changed files with 8 additions and 5 deletions
  1. 8
    5
      Marlin/src/gcode/queue.cpp

+ 8
- 5
Marlin/src/gcode/queue.cpp View File

@@ -170,16 +170,19 @@ bool GCodeQueue::process_injected_command() {
170 170
   char c;
171 171
   size_t i = 0;
172 172
   while ((c = pgm_read_byte(&injected_commands_P[i])) && c != '\n') i++;
173
-  if (i) {
174
-    char cmd[i + 1];
175
-    memcpy_P(cmd, injected_commands_P, i);
176
-    cmd[i] = '\0';
177 173
 
174
+  // Extract current command and move pointer to next command
175
+  char cmd[i + 1];
176
+  memcpy_P(cmd, injected_commands_P, i);
177
+  cmd[i] = '\0';
178
+  injected_commands_P = c ? injected_commands_P + i + 1 : nullptr;
179
+
180
+  // Execute command if non-blank
181
+  if (i) {
178 182
     parser.parse(cmd);
179 183
     PORT_REDIRECT(SERIAL_PORT);
180 184
     gcode.process_parsed_command();
181 185
   }
182
-  injected_commands_P = c ? injected_commands_P + i + 1 : nullptr;
183 186
   return true;
184 187
 }
185 188
 

Loading…
Cancel
Save