Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Output retrieving using empty OutputRef #1265

Closed
gabrielefronze opened this issue Jul 25, 2018 · 1 comment
Closed

Issue with Output retrieving using empty OutputRef #1265

gabrielefronze opened this issue Jul 25, 2018 · 1 comment

Comments

@gabrielefronze
Copy link
Contributor

Hello,

I found this issue with DPL Output retrieving using binding label.
Let's consider the following piece of code:

auto outputsPtr = std::make_shared<o2f::Outputs>(usrOutputs);
for (const auto& itOutputs : (*outputsPtr)) {
    auto fwdMsg = ctx.outputs().make<char>({ itOutputs.binding.value }, msgSize);
    std::memcpy(fwdMsg.data(), inputMsg.payload, msgSize);
}

At first the binding of the channels was not set in the usrOutputs elements, but the code was compiling correctly.
At runtime nothing bad happened if usrOutputs size was merely 1.
When using more than one channel the make call fell back to one of them without giving an error message, even if the retrieving using the binding string was faulty.

The issue should be related to DataAllocator::getOutputByBind, not checking for a non empty input string.
The following snippet should be a valid candidate for a fix.

  Output getOutputByBind(OutputRef&& ref)
  {
    if (ref.label == "") {
      throw std::runtime_error("Provided label is empty and cannot be used for OutputSpec retrieving");
      assert(false);
    }
    for (size_t ri = 0, re = mAllowedOutputRoutes.size(); ri != re; ++ri) {
      if (mAllowedOutputRoutes[ri].matcher.binding.value == ref.label) {
        auto spec = mAllowedOutputRoutes[ri].matcher;
        return Output{ spec.origin, spec.description, ref.subSpec, spec.lifetime, std::move(ref.headerStack) };
      }
    }
    throw std::runtime_error("Unable to find OutputSpec with label " + ref.label);
    assert(false);
  }

Cheers

Gabriele

@ktf
Copy link
Member

ktf commented Jul 25, 2018

Thanks for reporting this. Fix provided in #1267.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants