From c76b7b31ce1b3a369b9b6aa487153ed96db7c6cb Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Wed, 28 Aug 2002 09:10:03 +0000 Subject: [PATCH] Maximum instruction name is restricted to MAXLEN_INSTRUCTION. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@127 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- include/jtag/instruction.h | 4 +++- jtag/src/part/instruction.c | 11 +++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/jtag/instruction.h b/include/jtag/instruction.h index c96d59f1..0d79d8f8 100644 --- a/include/jtag/instruction.h +++ b/include/jtag/instruction.h @@ -28,10 +28,12 @@ #include #include +#define MAXLEN_INSTRUCTION 20 + typedef struct instruction instruction; struct instruction { - char *name; + char name[MAXLEN_INSTRUCTION + 1]; tap_register *value; data_register *data_register; instruction *next; diff --git a/jtag/src/part/instruction.c b/jtag/src/part/instruction.c index d6233656..19b601bf 100644 --- a/jtag/src/part/instruction.c +++ b/jtag/src/part/instruction.c @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -39,11 +40,10 @@ instruction_alloc( const char *name, int len, const char *val ) if (!i) return NULL; - i->name = strdup( name ); - if (!i->name) { - free( i ); - return NULL; - } + if (strlen( name ) > MAXLEN_INSTRUCTION) + printf( "Warning: Instruction too long\n" ); + strncpy( i->name, name, MAXLEN_INSTRUCTION ); + i->name[MAXLEN_INSTRUCTION] = '\0'; i->value = register_alloc( len ); if (!i->value) { @@ -65,7 +65,6 @@ instruction_free( instruction *i ) if (!i) return; - free( i->name ); register_free( i->value ); free( i ); }