From 10e8502717ef68230f085affe797dc237dffd533 Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Tue, 19 Oct 2021 18:25:28 +0200 Subject: [PATCH] remove sprintf from hole.h, plymc.h and volume.h --- vcg/complex/algorithms/create/plymc/plymc.h | 6 +++--- vcg/complex/algorithms/create/plymc/volume.h | 8 ++++---- vcg/complex/algorithms/hole.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vcg/complex/algorithms/create/plymc/plymc.h b/vcg/complex/algorithms/create/plymc/plymc.h index 9d6f5dca..c90f233d 100644 --- a/vcg/complex/algorithms/create/plymc/plymc.h +++ b/vcg/complex/algorithms/create/plymc/plymc.h @@ -597,7 +597,6 @@ int MCSimplify( MeshType &m, float absoluteError, bool preserveBB, vcg::CallBack //qDebug("Simplifying at absoluteError=%f",absoluteError); float TargetError = absoluteError; - char buf[1024]; DeciSession.template Init< MyColl > (); pp.areaThr=TargetError*TargetError; @@ -605,8 +604,9 @@ int MCSimplify( MeshType &m, float absoluteError, bool preserveBB, vcg::CallBack if(TargetError < std::numeric_limits::max() ) DeciSession.SetTargetMetric(TargetError); while(DeciSession.DoOptimization() && DeciSession.currMetric < TargetError) { - sprintf(buf,"Simplyfing %7i err %9g \r",m.fn,DeciSession.currMetric); - if (cb) cb(int(100.0f*DeciSession.currMetric/TargetError),buf); + std::string buf = "Simplyfing " + std::to_string(m.fn) + " err " + std::to_string(DeciSession.currMetric) + " \r"; + if (cb) + cb(int(100.0f*DeciSession.currMetric/TargetError),buf.c_str()); } return 1; //success diff --git a/vcg/complex/algorithms/create/plymc/volume.h b/vcg/complex/algorithms/create/plymc/volume.h index 0a9ba7fc..8f654ee9 100644 --- a/vcg/complex/algorithms/create/plymc/volume.h +++ b/vcg/complex/algorithms/create/plymc/volume.h @@ -42,7 +42,7 @@ const char *SFormat( const char * f, ... ) static char buf[4096]; va_list marker; va_start( marker, f ); - vsprintf(buf,f,marker); + vsnprintf(buf,4096,f,marker); va_end( marker ); return buf; } @@ -301,9 +301,9 @@ public: void GetSubVolumeTag(std::string &subtag) { char buf[32]; - if (div[0]<= 10 && div[1]<= 10 && div[2]<= 10 ) sprintf(buf,"_%01d%01d%01d",pos[0],pos[1],pos[2]); - else if(div[0]<= 100 && div[1]<= 100 && div[2]<= 100 ) sprintf(buf,"_%02d%02d%02d",pos[0],pos[1],pos[2]); - else sprintf(buf,"_%03d%03d%03d",pos[0],pos[1],pos[2]); + if (div[0]<= 10 && div[1]<= 10 && div[2]<= 10 ) snprintf(buf,32,"_%01d%01d%01d",pos[0],pos[1],pos[2]); + else if(div[0]<= 100 && div[1]<= 100 && div[2]<= 100 ) snprintf(buf,32,"_%02d%02d%02d",pos[0],pos[1],pos[2]); + else snprintf(buf,32,"_%03d%03d%03d",pos[0],pos[1],pos[2]); subtag=buf; } diff --git a/vcg/complex/algorithms/hole.h b/vcg/complex/algorithms/hole.h index ecb2256b..70e6aae7 100644 --- a/vcg/complex/algorithms/hole.h +++ b/vcg/complex/algorithms/hole.h @@ -291,8 +291,8 @@ public: typename MESH::ScalarType aspectRatio; const char * Dump() { static char buf[200]; - if(this->IsConcave()) sprintf(buf,"Dihedral -(deg) %6.2f Quality %6.2f\n",math::ToDeg(dihedralRad),aspectRatio); - else sprintf(buf,"Dihedral (deg) %6.2f Quality %6.2f\n",math::ToDeg(dihedralRad),aspectRatio); + if(this->IsConcave()) snprintf(buf,200,"Dihedral -(deg) %6.2f Quality %6.2f\n",math::ToDeg(dihedralRad),aspectRatio); + else snprintf(buf,200,"Dihedral (deg) %6.2f Quality %6.2f\n",math::ToDeg(dihedralRad),aspectRatio); return buf; }