From fad8521a87026e841b972e90794cc6224d4b5009 Mon Sep 17 00:00:00 2001 From: zwelch Date: Sat, 13 Jun 2009 00:33:01 +0000 Subject: [PATCH] Cleanup and fi handle_wait_halt_command: - Use unsigned type for delay variable. - Use parse_uint to ensure delay argument parses properly. - Bug fix: Return syntax error if more than one argument is given. - Bug fix: Return syntax error when argument fails to parse. git-svn-id: svn://svn.berlios.de/openocd/trunk@2227 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/target/target.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 13c0842f..2163a74c 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1822,21 +1822,23 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha static int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - int ms = 5000; + if (argc > 1) + return ERROR_COMMAND_SYNTAX_ERROR; - if (argc > 0) + unsigned ms = 5000; + if (1 == argc) { - char *end; - - ms = strtoul(args[0], &end, 0) * 1000; - if (*end) + int retval = parse_uint(args[0], &ms); + if (ERROR_OK != retval) { command_print(cmd_ctx, "usage: %s [seconds]", cmd); - return ERROR_OK; + return ERROR_COMMAND_SYNTAX_ERROR; } + // convert seconds (given) to milliseconds (needed) + ms *= 1000; } - target_t *target = get_current_target(cmd_ctx); + target_t *target = get_current_target(cmd_ctx); return target_wait_state(target, TARGET_HALTED, ms); } -- 2.39.5