Skip to content

Commit

Permalink
Merge pull request #2135 from Dennis40816/iox-2055-fix-convert-edge-c…
Browse files Browse the repository at this point in the history
…ases

Fix convert edge cases
  • Loading branch information
elBoberido authored Jan 2, 2024
2 parents 53fce2d + e02d08b commit fe3ef2e
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 526 deletions.
7 changes: 5 additions & 2 deletions iceoryx_examples/iceperf/main_follower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ int main(int argc, char* argv[])
{
constexpr decltype(EXIT_SUCCESS) MOO{EXIT_SUCCESS};

uint64_t intensity{0U};
if (!iox::convert::fromString(optarg, intensity))
auto result = iox::convert::from_string<uint64_t>(optarg);
if (!result.has_value())
{
std::cerr << "Could not parse 'intensity' paramater!" << std::endl;
return EXIT_FAILURE;
}

const auto intensity = result.value();

if (intensity > 100)
{
std::cerr << "Too high moo 'intensity'!" << std::endl;
Expand Down
6 changes: 5 additions & 1 deletion iceoryx_examples/iceperf/main_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@ int main(int argc, char* argv[])
}
break;
case 'n':
if (!iox::convert::fromString(optarg, settings.numberOfSamples))
{
auto result = iox::convert::from_string<uint64_t>(optarg);
if (!result.has_value())
{
std::cerr << "Could not parse 'number-of-samples' paramater!" << std::endl;
return EXIT_FAILURE;
}
settings.numberOfSamples = result.value();
break;
}
default:
return EXIT_FAILURE;
};
Expand Down
8 changes: 3 additions & 5 deletions iceoryx_hoofs/cli/include/iox/cli/arguments.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ namespace cli
template <typename T>
inline expected<T, Arguments::Error> Arguments::convertFromString(const Argument_t& stringValue) const noexcept
{
// @todo iox-#2055 there are edge cases which lead to not initializing the value even when the return value of
// 'fromString' is true; value initialization can be removed when #2055 is fixed
T value{};
if (!convert::fromString(stringValue.c_str(), value))
auto result = convert::from_string<T>(stringValue.c_str());
if (!result.has_value())
{
std::cout << "\"" << stringValue.c_str() << "\" could not be converted to the requested type" << std::endl;
return err(Error::UNABLE_TO_CONVERT_VALUE);
}
return ok(value);
return ok(result.value());
}

template <>
Expand Down
Loading

0 comments on commit fe3ef2e

Please sign in to comment.