diff --git a/src/axp.ino b/src/axp.ino index e18d700..cda5357 100644 --- a/src/axp.ino +++ b/src/axp.ino @@ -17,9 +17,9 @@ static AXP20X_Class axp; static uint32_t next_axp_log_millis; static uint32_t next_axp_report_millis; -static char str_axp_temp[10]; -static char str_axp_bus[20]; -static char str_axp_bat[60]; +static char str_axp_temp[10] = {'\0'}; +static char str_axp_bus[20] = {'\0'}; +static char str_axp_bat[60] = {'\0'}; // ---------------------------------------------------------------------------- bool axp_setup() { @@ -113,6 +113,8 @@ void axp_update_data() { // ---------------------------------------------------------------------------- char *axp_update_str(const char *fmt) { + if (str_axp_temp[0] == '\0' || str_axp_bus[0] == '\0' || str_axp_bat[0] == '\0') return NULL; + static char str[sizeof(str_axp_temp) + sizeof(str_axp_bus) + sizeof(str_axp_bat) + 10]; snprintf(str, sizeof(str), fmt, str_axp_temp, str_axp_bus, str_axp_bat); return str; diff --git a/src/gps.ino b/src/gps.ino index 025206d..a8a6489 100644 --- a/src/gps.ino +++ b/src/gps.ino @@ -25,9 +25,9 @@ static TinyGPSPlus gps; static uint32_t next_gps_stamp_millis; static uint32_t next_gps_report_millis; -static char str_gps_datetime[20]; -static char str_gps_loc[32]; -static char str_gps_quality[10]; +static char str_gps_datetime[20] = {'\0'}; +static char str_gps_loc[32] = {'\0'}; +static char str_gps_quality[10] = {'\0'}; // ---------------------------------------------------------------------------- void gps_setup(bool do_axp_exist) { @@ -91,6 +91,8 @@ void gps_update_data() { // ---------------------------------------------------------------------------- char *gps_update_str(const char *fmt) { + if (str_gps_datetime[0] == '\0' || str_gps_loc[0] == '\0' || str_gps_quality[0] == '\0') return NULL; + static char str[sizeof(str_gps_datetime) + sizeof(str_gps_loc) + sizeof(str_gps_quality) + 10]; snprintf(str, sizeof(str), fmt, str_gps_datetime, str_gps_loc, str_gps_quality); return str; diff --git a/src/lora.ino b/src/lora.ino index 99a0c18..7630188 100644 --- a/src/lora.ino +++ b/src/lora.ino @@ -106,6 +106,10 @@ bool report_status_to(Address sink) { // ---------------------------------------------------------------------------- bool report_gps_to(Address sink) { char *str = gps_update_str("@GPS %s\n%s\n%s\n"); + if (str == NULL) { + term_println("[LORA] report_gps_to(): gps_update_str() return NULL!"); + return false; + } uint8_t cnt = strlen(str); term_printf("[LORA] Report GPS node %d to %d, %d bytes:", getAddress(), sink, cnt); @@ -118,6 +122,10 @@ bool report_gps_to(Address sink) { // ---------------------------------------------------------------------------- bool report_axp_to(Address sink) { char *str = axp_update_str("@AXP %s\n%s\n%s\n"); + if (str == NULL) { + term_println("[LORA] report_axp_to(): axp_update_str() return NULL!"); + return false; + } uint8_t cnt = strlen(str); term_printf("[LORA] Report AXP node %d to %d, %d bytes:", getAddress(), sink, cnt);