From cd96faedba72f27eedc29d2be11ebe5cb8418ba8 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Mon, 26 Aug 2002 19:24:55 +0000 Subject: [PATCH] Added function register_duplicate(). Fixed possible segfault in register_get_string(). git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@108 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- include/jtag/register.h | 1 + jtag/src/tap/register.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/jtag/register.h b/include/jtag/register.h index c41a99c1..96055266 100644 --- a/include/jtag/register.h +++ b/include/jtag/register.h @@ -32,6 +32,7 @@ typedef struct tap_register { } tap_register; tap_register *register_alloc( int len ); +tap_register *register_duplicate( tap_register *tr ); void register_free( tap_register *tr ); tap_register *register_fill( tap_register *tr, int val ); const char *register_get_string( tap_register *tr ); diff --git a/jtag/src/tap/register.c b/jtag/src/tap/register.c index a7bc2d24..1abb84f9 100644 --- a/jtag/src/tap/register.c +++ b/jtag/src/tap/register.c @@ -58,6 +58,15 @@ register_alloc( int len ) return tr; } +tap_register * +register_duplicate( tap_register *tr ) +{ + if (!tr) + return NULL; + + return register_init( register_alloc( tr->len ), register_get_string( tr ) ); +} + void register_free( tap_register *tr ) { @@ -80,12 +89,13 @@ register_fill( tap_register *tr, int val ) const char * register_get_string( tap_register *tr ) { - if (tr) { - int i; + int i; - for (i = 0; i < tr->len; i++) - tr->string[tr->len - 1 - i] = (tr->data[i] & 1) ? '1' : '0'; - } + if (!tr) + return NULL; + + for (i = 0; i < tr->len; i++) + tr->string[tr->len - 1 - i] = (tr->data[i] & 1) ? '1' : '0'; return tr->string; }