From ff9cf35e8bd23c9d65b7ec60e2ee17d6f41b4517 Mon Sep 17 00:00:00 2001 From: stefanrueger Date: Sun, 16 Aug 2026 07:08:03 +0200 Subject: [PATCH] Reorder sanity checks in jtag3_paged_load() and jtag3_paged_load_tpi() --- src/jtag3.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/jtag3.c b/src/jtag3.c index ae9e6fc8..5cd5be5b 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -2096,15 +2096,15 @@ static int jtag3_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRME if((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) return -1; - if((resp && resp[1] != RSP3_DATA) || status < (int) block_size + 4) { - pmsg_error("wrong/short reply to read memory command\n"); - serial_recv_timeout = otimeout; + if(status < 4) { + pmsg_error("unexpected response from read memory jtag3_command()\n"); mmt_free(resp); return -1; } - if(status < 4) { - pmsg_error("unexpected response from read memory jtag3_command()\n"); + if((resp && resp[1] != RSP3_DATA) || status < (int) block_size + 4) { + pmsg_error("wrong/short reply to read memory command\n"); + serial_recv_timeout = otimeout; mmt_free(resp); return -1; } @@ -3166,15 +3166,15 @@ static int jtag3_paged_load_tpi(const PROGRAMMER *pgm, const AVRPART *p, if((status = jtag3_command_tpi(pgm, cmd, 8, &resp, "Read Memory")) < 0) return -1; - if((resp && resp[1] != XPRG_ERR_OK) || status < (int) block_size + 2) { - pmsg_error("wrong/short reply to read memory command\n"); - serial_recv_timeout = otimeout; + if(status < 2) { + pmsg_error("unexpected return value %d from jtag3_paged_load_tpi()\n", status); mmt_free(resp); return -1; } - if(status < 2) { - pmsg_error("unexpected return value %d from jtag3_paged_load_tpi()\n", status); + if((resp && resp[1] != XPRG_ERR_OK) || status < (int) block_size + 2) { + pmsg_error("wrong/short reply to read memory command\n"); + serial_recv_timeout = otimeout; mmt_free(resp); return -1; }