|
From: <zw...@ma...> - 2009-06-09 04:23:32
|
Author: zwelch
Date: 2009-06-09 04:23:27 +0200 (Tue, 09 Jun 2009)
New Revision: 2141
Modified:
trunk/src/jtag/jtag.c
Log:
Simplify and fix bug in jtag_tap_by_string:
- Bug fix: Use unsigned type and strtoul when parsing for position number.
- Simplify logic by returning directly when a tap is found by name.
- Reduce scope: declare temporary variables with first use.
- Bring code up to current style guidelines.
Modified: trunk/src/jtag/jtag.c
===================================================================
--- trunk/src/jtag/jtag.c 2009-06-09 02:23:16 UTC (rev 2140)
+++ trunk/src/jtag/jtag.c 2009-06-09 02:23:27 UTC (rev 2141)
@@ -279,31 +279,24 @@
*tap = t;
}
-jtag_tap_t *jtag_tap_by_string( const char *s )
+jtag_tap_t *jtag_tap_by_string(const char *s)
{
- jtag_tap_t *t;
+ /* try by name first */
+ jtag_tap_t *t = jtag_all_taps();
+ while (t)
+ {
+ if (0 == strcmp(t->dotted_name, s))
+ return t;
+ t = t->next_tap;
+ }
+
+ /* no tap found by name, so try to parse the name as a number */
char *cp;
+ unsigned n = strtoul(s, &cp, 0);
+ if ((s == cp) || (*cp != 0))
+ return NULL;
- t = jtag_all_taps();
- /* try name first */
- while(t){
- if( 0 == strcmp( t->dotted_name, s ) ){
- break;
- } else {
- t = t->next_tap;
- }
- }
- /* backup plan is by number */
- if( t == NULL ){
- /* ok - is "s" a number? */
- int n;
- n = strtol( s, &cp, 0 );
- if( (s != cp) && (*cp == 0) ){
- /* Then it is... */
- t = jtag_tap_by_abs_position(n);
- }
- }
- return t;
+ return jtag_tap_by_abs_position(n);
}
jtag_tap_t * jtag_tap_by_jim_obj( Jim_Interp *interp, Jim_Obj *o )
|