Skip to content

Commit b08b729

Browse files
committed
[#24280] Applied revision
Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent 4be9e2a commit b08b729

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

ddspipe_yaml/src/cpp/YamlReader_types.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*
1818
*/
1919

20+
#include <cmath>
21+
#include <limits>
22+
2023
#include <cpp_utils/Log.hpp>
2124
#include <cpp_utils/memory/Heritable.hpp>
2225
#include <cpp_utils/utils.hpp>
@@ -148,15 +151,16 @@ DomainId YamlReader::get<DomainId>(
148151
// Domain id required
149152
DomainId domain;
150153

151-
// Read as signed integer so negative values can be validated uniformly
152-
// by higher-level configuration checks instead of failing with a YAML cast error
153-
const auto domain_value = get_scalar<long long>(yml);
154-
const auto max_domain_id = static_cast<long long>(DomainId::MAX_DOMAIN_ID);
154+
// Read as double so numeric YAML values such as 0.5 do not fail with a cast error
155+
// Invalid values are marked and validated later in the configuration checks
156+
const auto domain_value = get_scalar<double>(yml);
157+
const auto max_domain_id = static_cast<double>(DomainId::MAX_DOMAIN_ID);
158+
const bool is_integer_domain = std::floor(domain_value) == domain_value;
155159

156-
if (domain_value < 0 || domain_value > max_domain_id)
160+
if (!std::isfinite(domain_value) || !is_integer_domain || domain_value < 0 || domain_value > max_domain_id)
157161
{
158162
// Mark as invalid and let configuration validation report a clear range error
159-
domain.domain_id = static_cast<DomainIdType>(DomainId::MAX_DOMAIN_ID + 1);
163+
domain.domain_id = static_cast<DomainIdType>(max_domain_id + 1);
160164
}
161165
else
162166
{
@@ -330,7 +334,21 @@ void YamlReader::fill(
330334
// Optional domain
331335
if (is_tag_present(yml, DDS_PUBLISHING_DOMAIN_TAG))
332336
{
333-
object.domain = get<DomainIdType>(yml, DDS_PUBLISHING_DOMAIN_TAG, version);
337+
// Read as double so numeric YAML values such as 0.5 do not fail with a cast error.
338+
// Invalid values are marked and validated later in the configuration checks.
339+
const auto domain_value = get<double>(yml, DDS_PUBLISHING_DOMAIN_TAG, version);
340+
const auto max_domain_value = static_cast<double>(std::numeric_limits<DomainIdType>::max());
341+
const bool is_integer_domain = std::floor(domain_value) == domain_value;
342+
343+
if (!std::isfinite(domain_value) || !is_integer_domain || domain_value < 0 || domain_value > max_domain_value)
344+
{
345+
// Mark as invalid and let configuration validation report a clear range error
346+
object.domain = static_cast<DomainIdType>(max_domain_value + 1);
347+
}
348+
else
349+
{
350+
object.domain = static_cast<DomainIdType>(domain_value);
351+
}
334352
}
335353

336354
// Optional topic name

0 commit comments

Comments
 (0)