Don't accept non-finite floats #4329

This commit is contained in:
Thomas Krijnen
2024-03-26 10:23:14 +01:00
parent b40c3fc173
commit a764387b90
2 changed files with 43 additions and 0 deletions
+32
View File
@@ -315,3 +315,35 @@ void IfcWriteArgument::set(IfcUtil::IfcBaseInterface* const& value) {
container_ = boost::blank();
}
}
void IfcWriteArgument::set(IfcUtil::IfcBaseInterface*const& v) {
if (v) {
container = v->as<IfcUtil::IfcBaseClass>();
} else {
container = boost::blank();
}
}
// Overloads to raise exceptions on non-finite values
void IfcWriteArgument::set(const double& v) {
if (!std::isfinite(v)) {
throw IfcParse::IfcException("Only finite values are allowed");
}
container = v;
}
void IfcWriteArgument::set(const std::vector<double>& v) {
if (std::any_of(v.begin(), v.end(), [](double v) {return !std::isfinite(v); })) {
throw IfcParse::IfcException("Only finite values are allowed");
}
container = v;
}
void IfcWriteArgument::set(const std::vector< std::vector<double> >& v) {
if (std::any_of(v.begin(), v.end(), [](const std::vector<double>& vs) {
return std::any_of(vs.begin(), vs.end(), [](double v) {return !std::isfinite(v); });
})) {
throw IfcParse::IfcException("Only finite values are allowed");
}
container = v;
}