From 4ecd13a9a3facb93f715b568222d5e88c0c29627 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 22 Dec 2018 20:47:38 +0100 Subject: [PATCH] nrf51: Fix crash with not argument given to "mon read". --- src/target/nrf51.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/target/nrf51.c b/src/target/nrf51.c index 182bf02..4b5da81 100644 --- a/src/target/nrf51.c +++ b/src/target/nrf51.c @@ -283,15 +283,15 @@ static bool nrf51_cmd_read_help(target *t) static bool nrf51_cmd_read(target *t, int argc, const char *argv[]) { const struct command_s *c; - - for(c = nrf51_read_cmd_list; c->cmd; c++) { - /* Accept a partial match as GDB does. - * So 'mon ver' will match 'monitor version' - */ - if(!strncmp(argv[1], c->cmd, strlen(argv[1]))) - return !c->handler(t, argc - 1, &argv[1]); + if (argc > 1) { + for(c = nrf51_read_cmd_list; c->cmd; c++) { + /* Accept a partial match as GDB does. + * So 'mon ver' will match 'monitor version' + */ + if(!strncmp(argv[1], c->cmd, strlen(argv[1]))) + return !c->handler(t, argc - 1, &argv[1]); + } } - return nrf51_cmd_read_help(t); }