diff --git a/subsys/modem/modem_ubx.c b/subsys/modem/modem_ubx.c index 22ce98f23eb..b463fb790b3 100644 --- a/subsys/modem/modem_ubx.c +++ b/subsys/modem/modem_ubx.c @@ -269,7 +269,9 @@ static void modem_ubx_process_handler(struct k_work *item) return; } - for (int i = 0; i < ret; i++) { + const size_t length = ret; + + for (int i = 0; i < length; i++) { ret = modem_ubx_process_received_byte(ubx, ubx->receive_buf[i]); if (ret == 0) { /* Frame matched successfully. Terminate the script. */ break;