fix null termination

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-03-15 23:51:55 +01:00
parent fab5b18389
commit f601990c67
4 changed files with 9 additions and 3 deletions
@@ -101,7 +101,7 @@ void wifi_manager_init()
ESP_ERROR_CHECK(esp_event_loop_create_default());
// Default WiFi Station
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
esp_netif_create_default_wifi_sta();
// Event Handler registrieren
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL));
@@ -130,7 +130,9 @@ void wifi_manager_init()
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
wifi_config_t wifi_config = {0};
strncpy((char *)wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid) - 1);
wifi_config.sta.ssid[sizeof(wifi_config.sta.ssid) - 1] = '\0';
strncpy((char *)wifi_config.sta.password, password, sizeof(wifi_config.sta.password) - 1);
wifi_config.sta.password[sizeof(wifi_config.sta.password) - 1] = '\0';
wifi_config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
@@ -51,7 +51,7 @@ extern "C"
typedef struct
{
char time[6];
char time[10];
uint8_t red;
uint8_t green;
uint8_t blue;
@@ -19,7 +19,7 @@
// Type definitions
typedef struct light_item_node_t
{
char time[5];
char time[4];
uint8_t red;
uint8_t green;
uint8_t blue;
@@ -210,6 +210,7 @@ static void send_simulation_message(const char *time, rgb_t color)
message_t msg = {};
msg.type = MESSAGE_TYPE_SIMULATION;
strncpy(msg.data.simulation.time, time, sizeof(msg.data.simulation.time) - 1);
msg.data.simulation.time[sizeof(msg.data.simulation.time) - 1] = '\0';
msg.data.simulation.red = color.red;
msg.data.simulation.green = color.green;
msg.data.simulation.blue = color.blue;
+3
View File
@@ -50,3 +50,6 @@ CONFIG_HTTPD_WS_SUPPORT=y
CONFIG_MQTT_CLIENT_BROKER_URL="mqtts://mqtt.mars3142.dev:8883"
CONFIG_MQTT_CLIENT_USERNAME="system-control"
CONFIG_MQTT_CLIENT_PASSWORD="3jHLhNPLcn_dPrukrpMJ"
# Compiler Options
CONFIG_COMPILER_DISABLE_DEFAULT_ERRORS=y