diff options
author | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-12 01:40:42 +0000 |
---|---|---|
committer | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-12 01:40:42 +0000 |
commit | 70d853b9fa823bd973b71e7003679c001dfdf196 (patch) | |
tree | 05eb2c9a88728338037268c0f18e90a41aa09bc3 | |
parent | 82403fe644663823cd730b364e7453fec2d49845 (diff) | |
download | openocd_libswd-70d853b9fa823bd973b71e7003679c001dfdf196.tar.gz openocd_libswd-70d853b9fa823bd973b71e7003679c001dfdf196.tar.bz2 openocd_libswd-70d853b9fa823bd973b71e7003679c001dfdf196.tar.xz openocd_libswd-70d853b9fa823bd973b71e7003679c001dfdf196.zip |
Improve handle_irscan_command:
- Use parse_u32 helper to ensure scan values are parsed properly.
- Clear the fields buffer to ensure partial cleanup occur correctly.
git-svn-id: svn://svn.berlios.de/openocd/trunk@2214 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r-- | src/jtag/tcl.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index eadfb431..557b6602 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1158,9 +1158,11 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c } int num_fields = argc / 2; + size_t fields_len = sizeof(scan_field_t) * num_fields; + fields = malloc(fields_len); + memset(fields, 0, fields_len); - fields = malloc(sizeof(scan_field_t) * num_fields); - + int retval; for (i = 0; i < num_fields; i++) { tap = jtag_tap_by_string( args[i*2] ); @@ -1173,17 +1175,26 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c fields[i].tap = tap; fields[i].num_bits = field_size; fields[i].out_value = malloc(CEIL(field_size, 8)); - buf_set_u32(fields[i].out_value, 0, field_size, strtoul(args[i*2+1], NULL, 0)); + + u32 value; + retval = parse_u32(args[i * 2 + 1], &value); + if (ERROR_OK != retval) + goto error_return; + buf_set_u32(fields[i].out_value, 0, field_size, value); fields[i].in_value = NULL; } /* did we have an endstate? */ jtag_add_ir_scan(num_fields, fields, endstate); - int retval=jtag_execute_queue(); + retval = jtag_execute_queue(); +error_return: for (i = 0; i < num_fields; i++) - free(fields[i].out_value); + { + if (NULL != fields[i].out_value) + free(fields[i].out_value); + } free (fields); |