Skip to content

Commit 0912889

Browse files
committed
raspberrypi: statically allocate storage for hostname
1 parent 84c7ac4 commit 0912889

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

ports/raspberrypi/common-hal/wifi/Radio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self) {
9292
}
9393

9494
void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname) {
95-
self->hostname = mp_obj_new_str(hostname, strlen(hostname));
96-
hostname = mp_obj_str_get_str(self->hostname);
97-
netif_set_hostname(NETIF_STA, hostname);
98-
netif_set_hostname(NETIF_AP, hostname);
95+
assert(strlen(hostname) < MP_ARRAY_SIZE(self->hostname));
96+
memcpy(self->hostname, hostname, strlen(hostname));
97+
netif_set_hostname(NETIF_STA, self->hostname);
98+
netif_set_hostname(NETIF_AP, self->hostname);
9999
}
100100

101101
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {

ports/raspberrypi/common-hal/wifi/Radio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
typedef struct {
3535
mp_obj_base_t base;
36-
mp_obj_t hostname;
36+
char hostname[254]; // hostname max is 253 chars, + 1 for trailing NUL
3737
wifi_scannednetworks_obj_t *current_scan;
3838
} wifi_radio_obj_t;
3939

0 commit comments

Comments
 (0)