Skip to content

Commit

Permalink
updated interpret_texture_name to include string len
Browse files Browse the repository at this point in the history
and substituted deprecated sprintf with snprintf
  • Loading branch information
cignoni committed Nov 30, 2023
1 parent 912e810 commit ab4a078
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
5 changes: 3 additions & 2 deletions wrap/io_trimesh/import_ply.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ class ImporterPLY
// Parsing texture names
m.textures.clear();
m.normalmaps.clear();
const size_t linesize=1024;

for(size_t co=0;co<pf.comments.size();++co)
{
Expand All @@ -1048,8 +1049,8 @@ class ImporterPLY
for(int i=0;i<n;i++)
if( bufstr[i]!=' ' && bufstr[i]!='\t' && bufstr[i]>32 && bufstr[i]<125 ) bufclean.push_back(bufstr[i]);

char buf2[255];
ply::interpret_texture_name( bufclean.c_str(),filename,buf2 );
char buf2[linesize];
ply::interpret_texture_name( bufclean.c_str(),filename,buf2,linesize );
m.textures.push_back( std::string(buf2) );
}
/*if( !strncmp(c,NFILE,strlen(NFILE)) )
Expand Down
8 changes: 5 additions & 3 deletions wrap/ply/plylib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3652,8 +3652,9 @@ int PlyFile::Read( void * mem )

return 0;
}

void interpret_texture_name(const char*a, const char*fn, char*output){
// this function is used to interpret the texture name in the ply header substituting "<this>" with the filename
// of the ply file itself. This is used to allow to rename the ply file without having to change the texture name inside the ply file
void interpret_texture_name(const char*a, const char*fn, char*output, size_t linesize){
int ia=0,io=0;
output[0]=0;
while (a[ia]!=0){
Expand Down Expand Up @@ -3685,7 +3686,8 @@ void interpret_texture_name(const char*a, const char*fn, char*output){

// 3) append
output[io]=0;
sprintf(output,"%s%s",output,fn2);
// replace sprintf(output,"%s%s",output,fn2);
snprintf(output, linesize, "%s%s",output,fn2);
io=strlen(output);
ia+=6; //skip the "<this>"
continue;
Expand Down
2 changes: 1 addition & 1 deletion wrap/ply/plylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class PlyFile
PlyElement * FindElement( const char * name );
};

void interpret_texture_name(const char*a, const char*fn, char*output);
void interpret_texture_name(const char*a, const char*fn, char*output, size_t linesize);

} // end namespace ply
} // end namespace vcg
Expand Down
23 changes: 0 additions & 23 deletions wrap/ply/plystuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,6 @@ of Greg Turk and on the work of Claudio Rocchini
****************************************************************************/

/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.6 2007/06/25 15:24:00 cignoni
removed a possibly useless static kw
Revision 1.5 2006/04/11 09:48:04 zifnab1974
changes needed for compilation on linux 64b with gcc 3.4.5
Revision 1.4 2005/12/02 00:00:53 cignoni
Moved and corrected interpret_texture_name from plystuff.h to plylib.cpp
Revision 1.3 2005/03/18 00:14:40 cignoni
removed small gcc compiling issues
Revision 1.2 2005/03/15 11:46:52 cignoni
Cleaning of the automatic bbox caching support for ply files. First working version.
*/

//****************** Gestione cache *****************

#ifndef __VCG_PLYLIB_STUFF
#define __VCG_PLYLIB_STUFF
Expand Down

0 comments on commit ab4a078

Please sign in to comment.