From 4f22de2333bcd9cfd603c144dd037358fc3c9d5f Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 6 Aug 2022 23:15:46 +0200 Subject: [PATCH] Do *not* shorten the current command in printer_smodel_check printer_smodel_check was incorrectly substituting the final " with a null in the command to simplify the model string comparison, but in doing so was also corrupting the next pop from the cmdqueue. We can modify the current strchr_pointer as long as we *don't* change it's length. This can cause an incorrect extra read from the queue, resulting in the last command to be completely ignored. --- Firmware/util.cpp | 7 +++---- Firmware/util.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Firmware/util.cpp b/Firmware/util.cpp index 7b192b8c3..3d789e08f 100644 --- a/Firmware/util.cpp +++ b/Firmware/util.cpp @@ -431,7 +431,7 @@ lcd_update_enable(true); // display / status-line recovery #define GCODE_DELIMITER '"' #define ELLIPSIS "..." -char* code_string(char* pStr,size_t* nLength) +char* code_string(const char* pStr,size_t* nLength) { char* pStrBegin; char* pStrEnd; @@ -444,11 +444,10 @@ pStrEnd=strchr(pStrBegin,GCODE_DELIMITER); if(!pStrEnd) return(NULL); *nLength=pStrEnd-pStrBegin; -pStrBegin[*nLength] = '\0'; return pStrBegin; } -void printer_smodel_check(char* pStrPos) +void printer_smodel_check(const char* pStrPos) { char* pResult; size_t nLength,nPrinterNameLength; @@ -458,7 +457,7 @@ pResult = code_string(pStrPos,&nLength); if(pResult != NULL && nLength == nPrinterNameLength) { // Only compare them if the lengths match - if (strcmp_P(pResult, sPrinterName) == 0) return; + if (strncmp_P(pResult, sPrinterName, nLength) == 0) return; } switch(oCheckModel) diff --git a/Firmware/util.h b/Firmware/util.h index 6d34aa081..7533429e2 100644 --- a/Firmware/util.h +++ b/Firmware/util.h @@ -104,7 +104,7 @@ extern ClCheckGcode oCheckGcode; void fCheckModeInit(); void nozzle_diameter_check(uint16_t nDiameter); void printer_model_check(uint16_t nPrinterModel); -void printer_smodel_check(char* pStrPos); +void printer_smodel_check(const char* pStrPos); void fw_version_check(const char *pVersion); void gcode_level_check(uint16_t nGcodeLevel);