Skip to content

Commit

Permalink
Update rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Lalancette <[email protected]>
Signed-off-by: Yadu <[email protected]>
  • Loading branch information
Yadunund and clalancette authored Aug 27, 2024
1 parent 8159b0b commit f2ee15e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,11 @@ std::optional<T> str_to_size_t(const std::string & str, const T default_value)
}
errno = 0;
char * endptr;
// TODO(Yadunund): strtoul and strtol both return long int and not size_t so we
// should consider fixing this implementation if this function is moved to
// a header file and will be used by other parts of the codebase.
size_t num = std::is_signed<decltype(default_value)>::value ?
strtol(str.c_str(), &endptr, 10) :
strtoul(str.c_str(), &endptr, 10);
// TODO(Yadunund): strtoul returns an unsigned long, not size_t.
// Depending on the architecture and platform, these may not be the same size.
// Further, if the incoming str is a signed integer, storing it in a size_t is incorrect.
// We should fix this piece of code to deal with both of those situations.
size_t num = strtoul(str.c_str(), &endptr, 10);
if (endptr == str.c_str()) {
// No values were converted, this is an error
RMW_SET_ERROR_MSG("no valid numbers available");
Expand Down

0 comments on commit f2ee15e

Please sign in to comment.