oappend robustness improvement

obuf is reset to nullptr in some cases
This commit is contained in:
Frank
2023-12-14 15:58:45 +01:00
committed by Frank
parent 47448b8d00
commit 9f71f47e6f

View File

@@ -148,11 +148,14 @@ bool oappendi(int i)
bool oappend(const char* txt) bool oappend(const char* txt)
{ {
uint16_t len = strlen(txt); uint16_t len = strlen(txt);
if (olen + len >= SETTINGS_STACK_BUF_SIZE) { if ((obuf == nullptr) || (olen + len >= SETTINGS_STACK_BUF_SIZE)) { // sanity checks
USER_PRINT(F("oappend() error: buffer full. Increase SETTINGS_STACK_BUF_SIZE for ")); if (obuf == nullptr) { USER_PRINTLN(F("oappend() error: obuf == nullptr."));
USER_PRINTF("%2u bytes \t\"", len /*1 + olen + len - SETTINGS_STACK_BUF_SIZE*/); } else {
USER_PRINT(txt); USER_PRINT(F("oappend() error: buffer full. Increase SETTINGS_STACK_BUF_SIZE for "));
USER_PRINTLN(F("\"")); USER_PRINTF("%2u bytes \t\"", len /*1 + olen + len - SETTINGS_STACK_BUF_SIZE*/);
USER_PRINT(txt);
USER_PRINTLN(F("\""));
}
return false; // buffer full return false; // buffer full
} }
strcpy(obuf + olen, txt); strcpy(obuf + olen, txt);