From 26cd98e48344ececfa8b024ddfa7d5dff2537e39 Mon Sep 17 00:00:00 2001 From: "Anders T. Akre" Date: Tue, 16 Jul 2024 10:31:00 +0200 Subject: [PATCH] modem: ubx: fix incoming byte processing `ret` holds the amount of bytes received from the modem. However during processing of the bytes its value is overwritten by the return value of `modem_ubx_process_received_byte`, in practice discarding all but the first byte read. To prevent this, store the length in a separate variable. Signed-off-by: Anders T. Akre --- subsys/modem/modem_ubx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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;