From 70d853b9fa823bd973b71e7003679c001dfdf196 Mon Sep 17 00:00:00 2001 From: zwelch Date: Fri, 12 Jun 2009 01:40:42 +0000 Subject: [PATCH] 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 --- src/jtag/tcl.c | 21 ++++++++++++++++----- 1 file 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); -- 2.39.5