From a6a06f47f6f34e176829752af569e4ae71dc23de Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sat, 1 Jan 2022 20:58:26 +0100 Subject: [PATCH] Prevent `spi' and `pgm' commands from crashing terminal mode These commands are been meaningful only on direct bitbang programming adapters which implement a pgm->setpin method. Disable these commands for all other programmers, and issue an informational message. This is a partial fix for bug #790. --- src/term.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/term.c b/src/term.c index f222fb46..28aa6253 100644 --- a/src/term.c +++ b/src/term.c @@ -733,18 +733,26 @@ static int cmd_help(PROGRAMMER * pgm, struct avrpart * p, static int cmd_spi(PROGRAMMER * pgm, struct avrpart * p, int argc, char * argv[]) { - pgm->setpin(pgm, PIN_AVR_RESET, 1); - spi_mode = 1; - return 0; + if (pgm->setpin != NULL) { + pgm->setpin(pgm, PIN_AVR_RESET, 1); + spi_mode = 1; + return 0; + } + avrdude_message(MSG_INFO, "`spi' command unavailable for this programmer type\n"); + return -1; } static int cmd_pgm(PROGRAMMER * pgm, struct avrpart * p, int argc, char * argv[]) { - pgm->setpin(pgm, PIN_AVR_RESET, 0); - spi_mode = 0; - pgm->initialize(pgm, p); - return 0; + if (pgm->setpin != NULL) { + pgm->setpin(pgm, PIN_AVR_RESET, 0); + spi_mode = 0; + pgm->initialize(pgm, p); + return 0; + } + avrdude_message(MSG_INFO, "`pgm' command unavailable for this programmer type\n"); + return -1; } static int cmd_verbose(PROGRAMMER * pgm, struct avrpart * p,