Skip to content

Commit

Permalink
Fix a couple of Linux C string manipulation warnings in picomodel, an…
Browse files Browse the repository at this point in the history
…d silence the remaining ones in md2_load
  • Loading branch information
codereader committed Oct 26, 2020
1 parent 4c5aa8e commit e386862
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions radiantcore/model/picomodel/lib/pm_3ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ static int GetMeshShader (T3dsLoaderPers *pers)

/* extract file name */
name = _pico_nopath( mapName );
strncpy( temp, name, sizeof(temp) );
memset( temp, 0, sizeof(temp) );
strncpy( temp, name, sizeof(temp)-1 );

/* remove file extension */
/* name = _pico_setfext( name,"" ); */
Expand Down Expand Up @@ -731,7 +732,7 @@ static picoModel_t *_3ds_load( PM_PARAMS_LOAD )
}
/* get model's base name (eg. jeep from c:\models\jeep.3ds) */
memset( basename,0,sizeof(basename) );
strncpy( basename,_pico_nopath(fileName),sizeof(basename) );
strncpy( basename,_pico_nopath(fileName),sizeof(basename)-1 );
_pico_setfext( basename,"" );

/* initialize persistant vars (formerly static) */
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/picomodel/lib/pm_ase.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD )
_ase_error_return("Node name parse error");

/* remember node name */
strncpy( lastNodeName,ptr,sizeof(lastNodeName) );
strncpy( lastNodeName,ptr,sizeof(lastNodeName)-1 );
}
/* model mesh (originally contained within geomobject) */
else if (!_pico_stricmp(p->token,"*mesh"))
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/model/picomodel/lib/pm_lwo.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ static picoModel_t *_lwo_load( PM_PARAMS_LOAD )
}

/* detox and set shader name */
strncpy( name, surface->name, sizeof(name) );
memset(name, 0, sizeof(name));
strncpy( name, surface->name, sizeof(name) - 1 );
_pico_first_token( name );
_pico_setfext( name, "" );
_pico_unixify( name );
Expand Down
12 changes: 7 additions & 5 deletions radiantcore/model/picomodel/lib/pm_md2.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ static int _md2_canload( PM_PARAMS_CANLOAD )


// _md2_load() loads a quake2 md2 model file.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#pragma GCC diagnostic ignored "-Wformat-truncation"

static picoModel_t *_md2_load( PM_PARAMS_LOAD )
{
Expand All @@ -341,7 +343,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD )
index_LUT_t *p_index_LUT;
md2Triangle_t *p_md2Triangle;

char skinname[ MD2_MAX_SKINNAME ];
char skinname[ MD2_MAX_SKINNAME + 1 ];
md2_t *md2;
md2St_t *texCoord;
md2Frame_t *frame;
Expand Down Expand Up @@ -458,8 +460,8 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD )

/* detox Skin name */
if (skinname[0] == '.') {/* special case ufoai skinpath */
char path[MD2_MAX_SKINNAME];
char skinnameRelative[MD2_MAX_SKINNAME];
char path[MD2_MAX_SKINNAME+1];
char skinnameRelative[MD2_MAX_SKINNAME+1];
strncpy(path, fileName, MD2_MAX_SKINNAME);
strncpy(skinnameRelative, skinname, MD2_MAX_SKINNAME);
_pico_unixify(path);
Expand Down Expand Up @@ -566,7 +568,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD )
return picoModel;
}


#pragma GCC diagnostic pop

/* pico file format module definition */
const picoModule_t picoModuleMD2 =
Expand Down

0 comments on commit e386862

Please sign in to comment.