Просмотр исходного кода

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.
Yuri D'Elia 2 лет назад
Родитель
Сommit
4f22de2333
2 измененных файлов с 4 добавлено и 5 удалено
  1. 3 4
      Firmware/util.cpp
  2. 1 1
      Firmware/util.h

+ 3 - 4
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)

+ 1 - 1
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);