diff options
author | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-13 00:33:34 +0000 |
---|---|---|
committer | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-13 00:33:34 +0000 |
commit | 6f9aac189206328568866244f471b5f27bbb0c45 (patch) | |
tree | acf50dff419c67559672e9724364de0fa0c219ec /src/target | |
parent | 08128b572ad0d7d8f113b9cf50cbb2a10e064804 (diff) | |
download | openocd_libswd-6f9aac189206328568866244f471b5f27bbb0c45.tar.gz openocd_libswd-6f9aac189206328568866244f471b5f27bbb0c45.tar.bz2 openocd_libswd-6f9aac189206328568866244f471b5f27bbb0c45.tar.xz openocd_libswd-6f9aac189206328568866244f471b5f27bbb0c45.zip |
Improve handle_mw_command argument handling:
- Change: All local variable types are now unsigned.
- Use parse_u32 to ensure address and value parse properly.
- Use parse_uint to ensure count parses properly.
- Move variables to location of first use.
git-svn-id: svn://svn.berlios.de/openocd/trunk@2231 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target')
-rw-r--r-- | src/target/target.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/target/target.c b/src/target/target.c index 755752bd..c2f479ad 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2074,22 +2074,30 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - u32 address = 0; - u32 value = 0; - int count = 1; - int i; - int wordsize; - target_t *target = get_current_target(cmd_ctx); - u8 value_buf[4]; - if ((argc < 2) || (argc > 3)) return ERROR_COMMAND_SYNTAX_ERROR; - address = strtoul(args[0], NULL, 0); - value = strtoul(args[1], NULL, 0); + u32 address; + int retval = parse_u32(args[0], &address); + if (ERROR_OK != retval) + return retval; + + u32 value; + retval = parse_u32(args[1], &value); + if (ERROR_OK != retval) + return retval; + + unsigned count = 1; if (argc == 3) - count = strtoul(args[2], NULL, 0); + { + retval = parse_uint(args[2], &count); + if (ERROR_OK != retval) + return retval; + } + target_t *target = get_current_target(cmd_ctx); + unsigned wordsize; + u8 value_buf[4]; switch (cmd[2]) { case 'w': @@ -2107,9 +2115,9 @@ static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char default: return ERROR_COMMAND_SYNTAX_ERROR; } - for (i=0; i<count; i++) + for (unsigned i = 0; i < count; i++) { - int retval = target_write_memory(target, + retval = target_write_memory(target, address + i * wordsize, wordsize, 1, value_buf); if (ERROR_OK != retval) return retval; |