Skip to content

Commit

Permalink
[core] Limit frequency values on registration layer so they don't bec…
Browse files Browse the repository at this point in the history
…ome negative. (#1961)
  • Loading branch information
KerstinKeller authored Jan 28, 2025
1 parent 3e073f3 commit d453403
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion ecal/core/src/pubsub/ecal_publisher_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <algorithm>
#include <chrono>
#include <functional>
#include <limits>
#include <mutex>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -935,6 +936,15 @@ namespace eCAL
{
const auto frequency_time = std::chrono::steady_clock::now();
const std::lock_guard<std::mutex> lock(m_frequency_calculator_mutex);
return static_cast<int32_t>(m_frequency_calculator.getFrequency(frequency_time) * 1000);

const double frequency_in_mhz = m_frequency_calculator.getFrequency(frequency_time) * 1000;

if (frequency_in_mhz > static_cast<double>(std::numeric_limits<int32_t>::max())) {
return std::numeric_limits<int32_t>::max();
}
else if (frequency_in_mhz < static_cast<double>(std::numeric_limits<int32_t>::min())) {
return std::numeric_limits<int32_t>::min();
}
return static_cast<int32_t>(frequency_in_mhz);
}
}
12 changes: 11 additions & 1 deletion ecal/core/src/pubsub/ecal_subscriber_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <chrono>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -961,6 +962,15 @@ namespace eCAL
{
const auto frequency_time = std::chrono::steady_clock::now();
const std::lock_guard<std::mutex> lock(m_frequency_calculator_mutex);
return static_cast<int32_t>(m_frequency_calculator.getFrequency(frequency_time) * 1000);

const double frequency_in_mhz = m_frequency_calculator.getFrequency(frequency_time) * 1000;

if (frequency_in_mhz > static_cast<double>(std::numeric_limits<int32_t>::max())) {
return std::numeric_limits<int32_t>::max();
}
else if (frequency_in_mhz < static_cast<double>(std::numeric_limits<int32_t>::min())) {
return std::numeric_limits<int32_t>::min();
}
return static_cast<int32_t>(frequency_in_mhz);
}
}

0 comments on commit d453403

Please sign in to comment.