Skip to content

Commit 9b15e1c

Browse files
starseekercshorler
authored andcommitted
Make a variety of adjustments to string printing, free temporary copy of EXPRto_String output.
1 parent 64873b4 commit 9b15e1c

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

src/exp2cxx/classes_type.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,9 +1026,9 @@ void TypeBody_Description( TypeBody body, char * buf ) {
10261026

10271027
const char * IdlEntityTypeName( Type t ) {
10281028
static char name [BUFSIZ+1];
1029-
strcpy( name, TYPE_PREFIX );
1029+
strncpy( name, TYPE_PREFIX, BUFSIZ );
10301030
if( TYPEget_name( t ) ) {
1031-
strcpy( name, FirstToUpper( TYPEget_name( t ) ) );
1031+
strncpy( name, FirstToUpper( TYPEget_name( t ) ), BUFSIZ );
10321032
} else {
10331033
return TYPEget_ctype( t );
10341034
}
@@ -1061,14 +1061,14 @@ const char * GetAggrElemType( const Type type ) {
10611061

10621062
/* case TYPE_ENTITY: */
10631063
if( class == entity_ ) {
1064-
strcpy( retval, IdlEntityTypeName( bt ) );
1064+
strncpy( retval, IdlEntityTypeName( bt ), BUFSIZ );
10651065
}
10661066

10671067
/* case TYPE_ENUM: */
10681068
/* case TYPE_SELECT: */
10691069
if( ( class == enumeration_ )
10701070
|| ( class == select_ ) ) {
1071-
strcpy( retval, TYPEget_ctype( bt ) );
1071+
strncpy( retval, TYPEget_ctype( bt ), BUFSIZ );
10721072
}
10731073

10741074
/* case TYPE_LOGICAL: */
@@ -1165,18 +1165,14 @@ const char * TYPEget_idl_type( const Type t ) {
11651165
/* case TYPE_ENTITY: */
11661166
if( class == entity_ ) {
11671167
/* better do this because the return type might go away */
1168-
strcpy( retval, IdlEntityTypeName( t ) );
1168+
strncpy( retval, IdlEntityTypeName( t ), BUFSIZ - 4 );
11691169
strcat( retval, "_ptr" );
11701170
return retval;
11711171
}
11721172
/* case TYPE_ENUM: */
11731173
/* case TYPE_SELECT: */
11741174
if( class == enumeration_ ) {
1175-
strncpy( retval, EnumName( TYPEget_name( t ) ), BUFSIZ - 2 );
1176-
1177-
strcat( retval, " /*" );
1178-
strcat( retval, IdlEntityTypeName( t ) );
1179-
strcat( retval, "*/ " );
1175+
snprintf( retval, BUFSIZ, "%s /*%s*/ ", EnumName(TYPEget_name(t)), IdlEntityTypeName(t) );
11801176
return retval;
11811177
}
11821178
if( class == select_ ) {
@@ -1201,9 +1197,8 @@ const char * TYPEget_idl_type( const Type t ) {
12011197
char * TYPEget_express_type( const Type t ) {
12021198
Class_Of_Type class;
12031199
Type bt;
1204-
char retval [BUFSIZ+1];
1205-
char * n, * permval, * aggr_type;
1206-
1200+
char retval [BUFSIZ+1] = {'\0'};
1201+
char * n = NULL, * permval = NULL, * aggr_type = NULL;
12071202

12081203
/* 1. "DEFINED" types */
12091204
/* case TYPE_ENUM: */
@@ -1293,7 +1288,9 @@ char * TYPEget_express_type( const Type t ) {
12931288
void AGGRprint_bound( FILE * header, FILE * impl, const char * var_name, const char * aggr_name, const char * cname, Expression bound, int boundNr ) {
12941289
if( bound->symbol.resolved ) {
12951290
if( bound->type == Type_Funcall ) {
1296-
fprintf( impl, " %s->SetBound%dFromExpressFuncall( \"%s\" );\n", var_name, boundNr, EXPRto_string( bound ) );
1291+
char *bound_str = EXPRto_string(bound);
1292+
fprintf( impl, " %s->SetBound%dFromExpressFuncall( \"%s\" );\n", var_name, boundNr, bound_str );
1293+
sc_free(bound_str);
12971294
} else {
12981295
fprintf( impl, " %s->SetBound%d( %d );\n", var_name, boundNr, bound->u.integer );
12991296
}

0 commit comments

Comments
 (0)