Skip to content

Commit af743ea

Browse files
committed
extmod/network_cyw43: Fix uninitialised variable in status('stations').
The `num_stas` was uninitialised and if it happened to take the value 0 then no results were returned. It now has the correct maximum value. Signed-off-by: Damien George <[email protected]>
1 parent f562aa1 commit af743ea

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

extmod/network_cyw43.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ static mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) {
361361
if (self->itf != CYW43_ITF_AP) {
362362
mp_raise_ValueError(MP_ERROR_TEXT("AP required"));
363363
}
364-
int num_stas;
365-
uint8_t macs[32 * 6];
364+
static const unsigned mac_len = 6;
365+
static const unsigned max_stas = 32;
366+
int num_stas = max_stas;
367+
uint8_t macs[max_stas * mac_len];
366368
cyw43_wifi_ap_get_stas(self->cyw, &num_stas, macs);
367369
mp_obj_t list = mp_obj_new_list(num_stas, NULL);
368370
for (int i = 0; i < num_stas; ++i) {
369371
mp_obj_t tuple[1] = {
370-
mp_obj_new_bytes(&macs[i * 6], 6),
372+
mp_obj_new_bytes(&macs[i * mac_len], mac_len),
371373
};
372374
((mp_obj_list_t *)MP_OBJ_TO_PTR(list))->items[i] = mp_obj_new_tuple(1, tuple);
373375
}

0 commit comments

Comments
 (0)