From 09128891068543f89633b4610c10f7707be91c14 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 30 Sep 2022 10:05:11 -0500 Subject: [PATCH] raspberrypi: statically allocate storage for hostname --- ports/raspberrypi/common-hal/wifi/Radio.c | 8 ++++---- ports/raspberrypi/common-hal/wifi/Radio.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index f4c22f789a..9ed69d6000 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -92,10 +92,10 @@ mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self) { } void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname) { - self->hostname = mp_obj_new_str(hostname, strlen(hostname)); - hostname = mp_obj_str_get_str(self->hostname); - netif_set_hostname(NETIF_STA, hostname); - netif_set_hostname(NETIF_AP, hostname); + assert(strlen(hostname) < MP_ARRAY_SIZE(self->hostname)); + memcpy(self->hostname, hostname, strlen(hostname)); + netif_set_hostname(NETIF_STA, self->hostname); + netif_set_hostname(NETIF_AP, self->hostname); } mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) { diff --git a/ports/raspberrypi/common-hal/wifi/Radio.h b/ports/raspberrypi/common-hal/wifi/Radio.h index 5e40e64ec6..0dc18c8957 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.h +++ b/ports/raspberrypi/common-hal/wifi/Radio.h @@ -33,7 +33,7 @@ typedef struct { mp_obj_base_t base; - mp_obj_t hostname; + char hostname[254]; // hostname max is 253 chars, + 1 for trailing NUL wifi_scannednetworks_obj_t *current_scan; } wifi_radio_obj_t;