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 ); }