Skip to content

Commit

Permalink
Add ill-defined parameters check.
Browse files Browse the repository at this point in the history
  • Loading branch information
drslebedev committed Aug 1, 2023
1 parent fc85aaf commit 8c5c140
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ class node : protected std::tuple<Arguments...> {
}

if (numerator != 1. || denominator != 1.) {
bool is_ill_defined = (denominator > ports_status.in_max_samples);
assert(!is_ill_defined);
if (is_ill_defined) {
return { requested_work, 0_UZ, work_return_status_t::ERROR };
}

ports_status.in_samples = static_cast<std::size_t>(ports_status.in_samples / denominator) * denominator; // remove reminder

const std::size_t out_min_limit = ports_status.out_min_samples;
Expand All @@ -627,7 +633,6 @@ class node : protected std::tuple<Arguments...> {
std::size_t in_max_wo_reminder = static_cast<std::size_t>(in_max_samples / denominator) * denominator;

if (ports_status.in_samples < in_min_wo_reminder) return { requested_work, 0_UZ, work_return_status_t::INSUFFICIENT_INPUT_ITEMS };

ports_status.in_samples = std::clamp(ports_status.in_samples, in_min_wo_reminder, in_max_wo_reminder);
ports_status.out_samples = numerator * (ports_status.in_samples / denominator);
}
Expand Down

0 comments on commit 8c5c140

Please sign in to comment.