Skip to content

Commit 93fb788

Browse files
committed
Merge branch 'master' of https://github.com/sofa-framework/sofa
2 parents 8d4a242 + 21e73df commit 93fb788

File tree

37 files changed

+511
-126
lines changed

37 files changed

+511
-126
lines changed

.github/workflows/launch-conda-packages-build.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,15 @@ jobs:
2525
token: ${{ secrets.PERF_REG_TOKEN }}
2626
path: SofaPython3
2727

28-
- name: Get commit info
28+
- name: Get SofaPython3 commit info
2929
run: |
3030
cd SofaPython3
3131
SOFA_PYTHON3_SHA=$(git rev-parse HEAD)
32-
SOFA_PYTHON3_COMMIT_DATE=$(git show -s --format=%cI HEAD)
32+
SOFA_PYTHON3_COMMIT_DATE=$(git show -s --date=format:%Y%m%d --format=%cd $SOFA_PYTHON3_SHA)
3333
3434
echo "SOFA_PYTHON3_SHA=$SOFA_PYTHON3_SHA" >> $GITHUB_ENV
3535
echo "SOFA_PYTHON3_COMMIT_DATE=$SOFA_PYTHON3_COMMIT_DATE" >> $GITHUB_ENV
3636
37-
- name: Get SOFA Python3 last commit and date on master
38-
run: |
39-
SOFA_PYTHON3_COMMIT_DATE=$(git show -s --date=format:%Y%m%d --format=%cd ${{ github.sha }})
40-
echo "COMMIT_DATE=$COMMIT_DATE" >> $GITHUB_ENV
41-
4237
- name: Launch build of development conda packages of SOFA
4338
run: |
4439
sudo apt install curl
@@ -48,4 +43,4 @@ jobs:
4843
-H "Authorization: Bearer ${{ secrets.PERF_REG_TOKEN }}" \
4944
-H "X-GitHub-Api-Version: 2022-11-28" \
5045
https://api.github.com/repos/sofa-framework/conda-ci/dispatches \
51-
-d '{"event_type":"build-devel-sofa-all","client_payload":{"sofa_commit_date":"$SOFA_COMMIT_DATE","sofa_commit_hash":"${{ github.sha }}","sofa_python3_commit_date":"$SOFA_PYTHON3_COMMIT_DATE","sofa_python3_commit_hash":"$SOFA_PYTHON3_SHA"}}'
46+
-d '{"event_type":"build-devel-sofa-all","client_payload":{"sofa_commit_date":"${{ env.SOFA_COMMIT_DATE }}","sofa_commit_hash":"${{ github.sha }}","sofa_python3_commit_hash":"${{ env.SOFA_PYTHON3_SHA }}","sofa_python3_commit_date":"${{ env.SOFA_PYTHON3_COMMIT_DATE }}"}}'

Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/RuleBasedContactManager.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
#include <sofa/component/collision/response/contact/config.h>
2424

2525
#include <sofa/component/collision/response/contact/CollisionResponse.h>
26+
#include <cstdlib>
27+
#include <cerrno>
28+
#include <climits>
29+
30+
#include <sofa/type/hardening.h>
2631

2732
namespace sofa::component::collision::response::contact
2833
{
@@ -46,18 +51,32 @@ class SOFA_COMPONENT_COLLISION_RESPONSE_CONTACT_API RuleBasedContactManager : pu
4651
in >> r.name1 >> r.name2 >> r.response;
4752
if (!r.name1.empty() && r.name1.find_first_not_of("-0123456789") == std::string::npos)
4853
{
49-
r.group1 = atoi(r.name1.c_str());
50-
r.name1.clear();
54+
int val{};
55+
if(sofa::type::hardening::safeStrToInt(r.name1, val))
56+
{
57+
r.group1 = val;
58+
r.name1.clear();
59+
}
60+
else
61+
r.group1 = 0;
5162
}
5263
else
5364
r.group1 = 0;
65+
5466
if (!r.name2.empty() && r.name2.find_first_not_of("-0123456789") == std::string::npos)
5567
{
56-
r.group2 = atoi(r.name2.c_str());
57-
r.name2.clear();
68+
int val{};
69+
if(sofa::type::hardening::safeStrToInt(r.name2, val))
70+
{
71+
r.group2 = val;
72+
r.name2.clear();
73+
}
74+
else
75+
r.group2 = 0;
5876
}
5977
else
6078
r.group2 = 0;
79+
6180
return in;
6281
}
6382

Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/TransformPosition.inl

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
#include <sofa/core/visual/VisualParams.h>
2525
#include <cmath>
2626
#include <sofa/helper/RandomGenerator.h>
27+
#include <sofa/type/hardening.h>
2728

2829
#include <vector>
2930
#include <iostream>
3031
#include <fstream>
3132
#include <algorithm>
33+
#include <cstdlib>
34+
#include <cerrno>
3235

3336
namespace sofa::component::engine::transform
3437
{
@@ -200,7 +203,17 @@ void TransformPosition<DataTypes>::getTransfoFromTfm()
200203
{
201204
std::string c = *it;
202205
if ( c.find_first_of("1234567890.-") != std::string::npos)
203-
values.push_back((Real)atof(c.c_str()));
206+
{
207+
Real val{};
208+
if(sofa::type::hardening::safeStrToScalar(c, val))
209+
{
210+
values.push_back(val);
211+
}
212+
else
213+
{
214+
msg_error() << "error while parsing value " << c ;
215+
}
216+
}
204217
}
205218

206219
if (values.size() != 12)
@@ -285,7 +298,14 @@ void TransformPosition<DataTypes>::getTransfoFromTrm()
285298
Coord tr;
286299
for ( unsigned int i = 0; i < std::min((unsigned int)vLine.size(),(unsigned int)3); i++)
287300
{
288-
tr[i] = mat(i,3) = (Real)atof(vLine[i].c_str());
301+
Real val{};
302+
if(!sofa::type::hardening::safeStrToScalar(vLine[i], val))
303+
{
304+
msg_error() << "Invalid number in file: " << vLine[i];
305+
val = 0.0;
306+
}
307+
308+
tr[i] = mat(i,3) = val;
289309
}
290310
f_translation.setValue(tr);
291311

@@ -294,7 +314,16 @@ void TransformPosition<DataTypes>::getTransfoFromTrm()
294314
{
295315
//rotation matrix
296316
for ( unsigned int i = 0; i < std::min((unsigned int)vLine.size(),(unsigned int)3); i++)
297-
mat(nbLines-2,i) = (Real)atof(vLine[i].c_str());
317+
{
318+
Real val{};
319+
if(!sofa::type::hardening::safeStrToScalar(vLine[i], val))
320+
{
321+
msg_error() << "Invalid number in file: " << vLine[i];
322+
val = 0.0;
323+
}
324+
325+
mat(nbLines-2,i) = val;
326+
}
298327
}
299328

300329
}
@@ -358,7 +387,16 @@ void TransformPosition<DataTypes>::getTransfoFromTxt()
358387
else if (vLine.size()<4) {msg_error() << "Matrix is not 4x4.";continue;}
359388

360389
for ( unsigned int i = 0; i < std::min((unsigned int)vLine.size(),(unsigned int)4); i++)
361-
mat(nbLines-1,i) = (Real)atof(vLine[i].c_str());
390+
{
391+
Real val{};
392+
if(!sofa::type::hardening::safeStrToScalar(vLine[i], val))
393+
{
394+
msg_error() << "Invalid number in file: " << vLine[i];
395+
val = 0.0;
396+
}
397+
398+
mat(nbLines-1,i) = (Real)val;
399+
}
362400
}
363401
f_affineMatrix.setValue(mat);
364402

Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshGmshLoader.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ bool MeshGmshLoader::doLoad()
6464
// NB: .msh file header line for version >= 2 can be "$MeshFormat", "$MeshFormat\r", "$MeshFormat \r"
6565
string version;
6666
std::getline(file, version); // Getting the version line (e.g. 4.1 0 8)
67-
gmshFormat = std::stoul( version.substr( 0, version.find(" ")) ); // Retrieving the mesh format, keeping only the integer part
67+
try
68+
{
69+
gmshFormat = std::stoul( version.substr( 0, version.find(" ")) ); // Retrieving the mesh format, keeping only the integer part
70+
}
71+
catch (const std::exception&)
72+
{
73+
msg_error() << "Invalid mesh format version in file header: '" << version << "'. Closing File";
74+
file.close();
75+
return false;
76+
}
6877
std::getline(file, cmd); // $EndMeshFormat
6978

7079
if (cmd.length() < 14 || cmd.substr(0, 14) != string("$EndMeshFormat")) // it should end with "$EndMeshFormat" or "$EndMeshFormat\r"

Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshOBJLoader.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
#include <sofa/core/ObjectFactory.h>
2525
#include <sofa/helper/system/SetDirectory.h>
2626
#include <fstream>
27+
#include <cstdlib>
28+
#include <cerrno>
29+
#include <climits>
2730
#include <sofa/helper/accessor.h>
2831
#include <sofa/helper/system/Locale.h>
32+
#include <sofa/type/hardening.h>
2933

3034
namespace sofa::component::io::mesh
3135
{
@@ -306,16 +310,23 @@ bool MeshOBJLoader::readOBJ (std::ifstream &file, const char* filename)
306310

307311
if (!tmp.empty())
308312
{
309-
vtn[j] = atoi(tmp.c_str());
310-
if (vtn[j] >= 1)
311-
vtn[j] -=1; // -1 because the numerotation begins at 1 and a vector begins at 0
312-
else if (vtn[j] < 0)
313-
vtn[j] += (j==0) ? sofa::Size(my_positions.size()) : (j==1) ? sofa::Size(my_texCoords.size()) : sofa::Size(my_normals.size());
314-
else
313+
if(!sofa::type::hardening::safeStrToInt(tmp, vtn[j]))
315314
{
316315
msg_error() << "Invalid index " << tmp;
317316
vtn[j] = -1;
318317
}
318+
else
319+
{
320+
if (vtn[j] >= 1)
321+
vtn[j] -=1; // -1 because the numerotation begins at 1 and a vector begins at 0
322+
else if (vtn[j] < 0)
323+
vtn[j] += (j==0) ? sofa::Size(my_positions.size()) : (j==1) ? sofa::Size(my_texCoords.size()) : sofa::Size(my_normals.size());
324+
else
325+
{
326+
msg_error() << "Invalid index " << tmp;
327+
vtn[j] = -1;
328+
}
329+
}
319330
}
320331
}
321332

Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/OffSequenceLoader.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222

2323
#include <sofa/component/io/mesh/OffSequenceLoader.h>
2424
#include <sofa/core/visual/VisualParams.h>
25+
#include <sofa/type/hardening.h>
2526

2627
#include <sofa/simulation/AnimateBeginEvent.h>
2728
#include <sofa/core/ObjectFactory.h>
2829
#include <sstream>
2930
#include <fstream>
31+
#include <cstdlib>
32+
#include <cerrno>
33+
#include <climits>
3034

3135
namespace sofa::component::io::mesh
3236
{
@@ -88,7 +92,16 @@ void OffSequenceLoader::init()
8892
while ( m_filenameAndNb[--indCar] >= '0' && m_filenameAndNb[indCar] <= '9')
8993
fileNb.insert(0, 1, m_filenameAndNb[indCar]);
9094

91-
currentIndex = firstIndex = atoi(fileNb.c_str());
95+
96+
if(sofa::type::hardening::safeStrToInt(fileNb, firstIndex))
97+
{
98+
currentIndex = firstIndex;
99+
}
100+
else
101+
{
102+
msg_error() << "Invalid file index: " << fileNb;
103+
currentIndex = firstIndex = 0;
104+
}
92105
}
93106

94107

Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ bool STLExporter::writeSTLBinary(bool autonumbering)
260260
{
261261
buffer[i]='\0';
262262
}
263-
strcpy(buffer, "Exported from Sofa");
264-
outfile.write(buffer,80);
263+
strncpy(buffer, "Exported from Sofa", 18);
265264

266265
/* Number of d_facets */
267266
const unsigned int nbt = vecTri.size();

Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/StaticSolver.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@ void StaticSolver::parse(core::objectmodel::BaseObjectDescription* arg)
5555
{
5656
if (const char* attribute = arg->getAttribute(data.m_name))
5757
{
58-
data.value.emplace(std::stod(attribute));
59-
msg_warning() << "The attribute '" << data.m_name
60-
<< "' is no longer defined in this component. Instead, define the attribute '"
61-
<< newAttributeName << "' in the NewtonRaphsonSolver component associated with this StaticSolver.";
58+
try
59+
{
60+
data.value.emplace(std::stod(attribute));
61+
msg_warning() << "The attribute '" << data.m_name
62+
<< "' is no longer defined in this component. Instead, define the attribute '"
63+
<< newAttributeName << "' in the NewtonRaphsonSolver component associated with this StaticSolver.";
64+
}
65+
catch (const std::exception&)
66+
{
67+
msg_warning() << "Invalid value '" << attribute << "' for deprecated attribute '" << data.m_name << "'";
68+
}
6269
}
6370
};
6471

Sofa/GL/src/sofa/gl/Capture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ std::string Capture::findFilename()
9999
do
100100
{
101101
++c;
102-
sprintf(buf, "%08d",c);
102+
snprintf(buf, sizeof(buf), "%08d",c);
103103
filename = prefix;
104104
filename += buf;
105105
if(pngSupport)
@@ -110,7 +110,7 @@ std::string Capture::findFilename()
110110
while (stat(filename.c_str(),&st)==0);
111111
counter = c+1;
112112

113-
sprintf(buf, "%08d",c);
113+
snprintf(buf, sizeof(buf), "%08d",c);
114114
filename = prefix;
115115
filename += buf;
116116
if(pngSupport)

Sofa/GL/src/sofa/gl/VideoRecorderFFMPEG.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ void VideoRecorderFFMPEG::finishVideo()
194194
pclose(m_ffmpeg);
195195
#endif
196196

197-
delete m_ffmpegBuffer;
198-
delete m_viewportBuffer;
197+
delete[] m_ffmpegBuffer;
198+
delete[] m_viewportBuffer;
199199
std::cout << m_filename << " written" << std::endl;
200200
}
201201

@@ -209,7 +209,7 @@ std::string VideoRecorderFFMPEG::findFilename(const unsigned int framerate, cons
209209
do
210210
{
211211
++c;
212-
sprintf(buf, "%04d", c);
212+
snprintf(buf, sizeof(buf), "%04d", c);
213213
filename = m_prefix;
214214
filename += "_r" + std::to_string(framerate) + "_";
215215
//filename += +"_b" + std::to_string(bitrate) + "_";

0 commit comments

Comments
 (0)