diff options
| author | Damien George <damien@micropython.org> | 2024-11-19 11:26:34 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-11-20 14:23:20 +1100 |
| commit | af743eaf59196e9133bd3c6de53cae1bb6c9a59a (patch) | |
| tree | ead8604805192267dca24ed12f0b73322772ba8f | |
| parent | f562aa1291ad44605f6b5be75b325a40a208ec41 (diff) | |
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 <damien@micropython.org>
| -rw-r--r-- | extmod/network_cyw43.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index 891e945de..cebc8deb0 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -361,13 +361,15 @@ static mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) { if (self->itf != CYW43_ITF_AP) { mp_raise_ValueError(MP_ERROR_TEXT("AP required")); } - int num_stas; - uint8_t macs[32 * 6]; + static const unsigned mac_len = 6; + static const unsigned max_stas = 32; + int num_stas = max_stas; + uint8_t macs[max_stas * mac_len]; cyw43_wifi_ap_get_stas(self->cyw, &num_stas, macs); mp_obj_t list = mp_obj_new_list(num_stas, NULL); for (int i = 0; i < num_stas; ++i) { mp_obj_t tuple[1] = { - mp_obj_new_bytes(&macs[i * 6], 6), + mp_obj_new_bytes(&macs[i * mac_len], mac_len), }; ((mp_obj_list_t *)MP_OBJ_TO_PTR(list))->items[i] = mp_obj_new_tuple(1, tuple); } |
