Browse Source

utils: mdldec: remove usage of string functions with unspecified size

pull/2/head
Alibek Omarov 2 years ago
parent
commit
76c7273600
  1. 12
      utils/mdldec/mdldec.c
  2. 38
      utils/mdldec/qc.c

12
utils/mdldec/mdldec.c

@ -86,7 +86,7 @@ static void BoneNameFix( void )
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i; bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
if( bone->name[0] == '\0' ) if( bone->name[0] == '\0' )
Q_sprintf( bone->name, "MDLDEC_Bone%i", ++counter ); Q_snprintf( bone->name, sizeof( bone->name ), "MDLDEC_Bone%i", ++counter );
} }
if( counter ) if( counter )
@ -179,8 +179,8 @@ static qboolean LoadMDL( const char *modelname )
if( !model_hdr->numtextures ) if( !model_hdr->numtextures )
{ {
Q_strcpy( texturename, modelname ); Q_strncpy( texturename, modelname, sizeof( texturename ));
Q_strcpy( &texturename[len], "t.mdl" ); Q_strncpy( &texturename[len], "t.mdl", sizeof( texturename ) - len );
texture_hdr = (studiohdr_t *)LoadFile( texturename ); texture_hdr = (studiohdr_t *)LoadFile( texturename );
@ -222,11 +222,11 @@ static qboolean LoadMDL( const char *modelname )
if( model_hdr->numseqgroups > 1 ) if( model_hdr->numseqgroups > 1 )
{ {
Q_strcpy( seqgroupname, modelname ); Q_strncpy( seqgroupname, modelname, sizeof( seqgroupname ));
for( i = 1; i < model_hdr->numseqgroups; i++ ) for( i = 1; i < model_hdr->numseqgroups; i++ )
{ {
Q_sprintf( &seqgroupname[len], "%02d.mdl", i ); Q_snprintf( &seqgroupname[len], sizeof( seqgroupname ) - len, "%02d.mdl", i );
anim_hdr[i] = (studiohdr_t *)LoadFile( seqgroupname ); anim_hdr[i] = (studiohdr_t *)LoadFile( seqgroupname );
@ -283,7 +283,7 @@ int main( int argc, char *argv[] )
goto end; goto end;
} }
Q_strcpy( destdir, argv[2] ); Q_strncpy( destdir, argv[2], sizeof( destdir ));
} }
if( !LoadActivityList( argv[0] ) || !LoadMDL( argv[1] ) ) if( !LoadActivityList( argv[0] ) || !LoadMDL( argv[1] ) )

38
utils/mdldec/qc.c

@ -110,7 +110,7 @@ static const char *FindActivityName( int type )
GetMotionTypeString GetMotionTypeString
============ ============
*/ */
static void GetMotionTypeString( int type, char *str, qboolean is_composite ) static void GetMotionTypeString( int type, char *str, size_t size, qboolean is_composite )
{ {
const char *p = NULL; const char *p = NULL;
@ -119,46 +119,46 @@ static void GetMotionTypeString( int type, char *str, qboolean is_composite )
if( is_composite ) if( is_composite )
{ {
if( type & STUDIO_X ) if( type & STUDIO_X )
Q_strcat( str, " X" ); Q_strncat( str, " X", size );
if( type & STUDIO_Y ) if( type & STUDIO_Y )
Q_strcat( str, " Y" ); Q_strncat( str, " Y", size );
if( type & STUDIO_Z ) if( type & STUDIO_Z )
Q_strcat( str, " Z" ); Q_strncat( str, " Z", size );
if( type & STUDIO_XR ) if( type & STUDIO_XR )
Q_strcat( str, " XR" ); Q_strncat( str, " XR", size );
if( type & STUDIO_YR ) if( type & STUDIO_YR )
Q_strcat( str, " YR" ); Q_strncat( str, " YR", size );
if( type & STUDIO_ZR ) if( type & STUDIO_ZR )
Q_strcat( str, " ZR" ); Q_strncat( str, " ZR", size );
if( type & STUDIO_LX ) if( type & STUDIO_LX )
Q_strcat( str, " LX" ); Q_strncat( str, " LX", size );
if( type & STUDIO_LY ) if( type & STUDIO_LY )
Q_strcat( str, " LY" ); Q_strncat( str, " LY", size );
if( type & STUDIO_LZ ) if( type & STUDIO_LZ )
Q_strcat( str, " LZ" ); Q_strncat( str, " LZ", size );
if( type & STUDIO_LXR ) if( type & STUDIO_LXR )
Q_strcat( str, " LXR" ); Q_strncat( str, " LXR", size );
if( type & STUDIO_LYR ) if( type & STUDIO_LYR )
Q_strcat( str, " LYR" ); Q_strncat( str, " LYR", size );
if( type & STUDIO_LZR ) if( type & STUDIO_LZR )
Q_strcat( str, " LZR" ); Q_strncat( str, " LZR", size );
if( type & STUDIO_LINEAR ) if( type & STUDIO_LINEAR )
Q_strcat( str, " LM" ); Q_strncat( str, " LM", size );
if( type & STUDIO_QUADRATIC_MOTION ) if( type & STUDIO_QUADRATIC_MOTION )
Q_strcat( str, " LQ" ); Q_strncat( str, " LQ", size );
return; return;
} }
@ -185,7 +185,7 @@ static void GetMotionTypeString( int type, char *str, qboolean is_composite )
} }
if( p ) if( p )
Q_strcpy( str, p ); Q_strncpy( str, p, size );
} }
/* /*
@ -380,7 +380,7 @@ static void WriteControllerInfo( FILE *fp )
bonecontroller = (mstudiobonecontroller_t *)( (byte *)model_hdr + model_hdr->bonecontrollerindex ) + i; bonecontroller = (mstudiobonecontroller_t *)( (byte *)model_hdr + model_hdr->bonecontrollerindex ) + i;
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + bonecontroller->bone; bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + bonecontroller->bone;
GetMotionTypeString( bonecontroller->type & ~STUDIO_RLOOP, motion_types, false ); GetMotionTypeString( bonecontroller->type & ~STUDIO_RLOOP, motion_types, sizeof( motion_types ), false );
fprintf( fp, "$controller %i \"%s\" %s %f %f\n", fprintf( fp, "$controller %i \"%s\" %s %f %f\n",
bonecontroller->index, bone->name, motion_types, bonecontroller->index, bone->name, motion_types,
@ -464,7 +464,7 @@ static void WriteSequenceInfo( FILE *fp )
fprintf( fp, "\"%s_blend2\" ", seqdesc->label ); fprintf( fp, "\"%s_blend2\" ", seqdesc->label );
} }
GetMotionTypeString( seqdesc->blendtype[0], motion_types, false ); GetMotionTypeString( seqdesc->blendtype[0], motion_types, sizeof( motion_types ), false );
fprintf( fp, "blend %s %.0f %.0f", fprintf( fp, "blend %s %.0f %.0f",
motion_types, seqdesc->blendstart[0], seqdesc->blendend[0] ); motion_types, seqdesc->blendstart[0], seqdesc->blendend[0] );
@ -476,7 +476,7 @@ static void WriteSequenceInfo( FILE *fp )
if( seqdesc->motiontype ) if( seqdesc->motiontype )
{ {
GetMotionTypeString( seqdesc->motiontype, motion_types, true ); GetMotionTypeString( seqdesc->motiontype, motion_types, sizeof( motion_types ), true );
fprintf( fp, "%s", motion_types ); fprintf( fp, "%s", motion_types );
} }

Loading…
Cancel
Save