Fix process_injected_command undefined behavior (#14602)
This commit is contained in:
		
				
					committed by
					
						
						Scott Lahteine
					
				
			
			
				
	
			
			
			
						parent
						
							e139c1d9d9
						
					
				
				
					commit
					cbe4bf2ba8
				
			@@ -170,16 +170,19 @@ bool GCodeQueue::process_injected_command() {
 | 
				
			|||||||
  char c;
 | 
					  char c;
 | 
				
			||||||
  size_t i = 0;
 | 
					  size_t i = 0;
 | 
				
			||||||
  while ((c = pgm_read_byte(&injected_commands_P[i])) && c != '\n') i++;
 | 
					  while ((c = pgm_read_byte(&injected_commands_P[i])) && c != '\n') i++;
 | 
				
			||||||
  if (i) {
 | 
					
 | 
				
			||||||
 | 
					  // Extract current command and move pointer to next command
 | 
				
			||||||
  char cmd[i + 1];
 | 
					  char cmd[i + 1];
 | 
				
			||||||
  memcpy_P(cmd, injected_commands_P, i);
 | 
					  memcpy_P(cmd, injected_commands_P, i);
 | 
				
			||||||
  cmd[i] = '\0';
 | 
					  cmd[i] = '\0';
 | 
				
			||||||
 | 
					  injected_commands_P = c ? injected_commands_P + i + 1 : nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Execute command if non-blank
 | 
				
			||||||
 | 
					  if (i) {
 | 
				
			||||||
    parser.parse(cmd);
 | 
					    parser.parse(cmd);
 | 
				
			||||||
    PORT_REDIRECT(SERIAL_PORT);
 | 
					    PORT_REDIRECT(SERIAL_PORT);
 | 
				
			||||||
    gcode.process_parsed_command();
 | 
					    gcode.process_parsed_command();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  injected_commands_P = c ? injected_commands_P + i + 1 : nullptr;
 | 
					 | 
				
			||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user