]> git.sur5r.net Git - openocd/commitdiff
tcl/drscan: handle invalid syntax with a conditional, not assert
authorPaul Fertser <fercerpav@gmail.com>
Tue, 4 Feb 2014 12:07:57 +0000 (16:07 +0400)
committerSpencer Oliver <spen@spen-soft.co.uk>
Mon, 24 Feb 2014 12:01:52 +0000 (12:01 +0000)
When "drscan" command is used improperly, such as in:
drscan stm32f1x.cpu -endstate drpause
there're no fields to scan, and so the assert leads to a
segfault. This should be treated like any other syntax error instead.

Change-Id: Id1743f5d641038e1e3754c6f3097aabc5d1916b9
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/1927
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/jtag/tcl.c

index ceea19303c53e8debad0d8eee4473efbb9a24d31..dd2be1e5ad3f58e06794d5440841d559704aaf16 100644 (file)
@@ -169,7 +169,10 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
                return JIM_ERR;
 
        num_fields = (argc-2)/2;
-       assert(num_fields > 0);
+       if (num_fields <= 0) {
+               Jim_SetResultString(interp, "drscan: no scan fields supplied", -1);
+               return JIM_ERR;
+       }
        fields = malloc(sizeof(struct scan_field) * num_fields);
        for (i = 2; i < argc; i += 2) {
                long bits;