#4329 Don't accept non-finite floats

This commit is contained in:
Thomas Krijnen
2024-03-26 10:23:14 +01:00
parent e5fd6d9152
commit 55885f7a24
2 changed files with 31 additions and 2 deletions
+25 -1
View File
@@ -295,4 +295,28 @@ void IfcWriteArgument::set(IfcUtil::IfcBaseInterface*const& v) {
} 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;
}
+6 -1
View File
@@ -142,7 +142,12 @@ namespace IfcWrite {
// Overload to detect null values
void set(IfcUtil::IfcBaseInterface*const & v);
// Overloads to raise exceptions on non-finite values
void set(const double& v);
void set(const std::vector<double>& v);
void set(const std::vector< std::vector<double> >& v);
operator int() const;
operator bool() const;
operator boost::logic::tribool() const;