Skip to content

Commit

Permalink
Fix for incorrect integer value conversion on Windows (#1126)
Browse files Browse the repository at this point in the history
* Fix for incorrect integer value conversion on Windows

- Replace srtol(..) to the strtoll(..)

Signed-off-by: Michael Orlov <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
  • Loading branch information
MichaelOrlov and clalancette committed Dec 21, 2023
1 parent 246fd1d commit 7bcc293
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rcl_yaml_param_parser/src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ void * get_value(
style != YAML_DOUBLE_QUOTED_SCALAR_STYLE)
{
errno = 0;
ival = strtol(value, &endptr, 0);
ival = strtoll(value, &endptr, 0);
if ((0 == errno) && (NULL != endptr)) {
if ((NULL != endptr) && (endptr != value)) {
if (endptr != value) {
if (('\0' != *value) && ('\0' == *endptr)) {
*val_type = DATA_TYPE_INT64;
ret_val = allocator.zero_allocate(1U, sizeof(int64_t), allocator.state);
Expand Down
2 changes: 1 addition & 1 deletion rcl_yaml_param_parser/test/correct_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lidar_ns:
dy: 0.45
lidar_2:
ros__parameters:
id: 11
id: 992147483647
name: back_lidar
dy1: 0.003
is_back: false
Expand Down
3 changes: 2 additions & 1 deletion rcl_yaml_param_parser/test/test_parse_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ TEST(test_parser, correct_syntax) {
param_value = rcl_yaml_node_struct_get("lidar_ns/lidar_2", "id", params);
ASSERT_TRUE(NULL != param_value) << rcutils_get_error_string().str;
ASSERT_TRUE(NULL != param_value->integer_value);
EXPECT_EQ(11, *param_value->integer_value);
// Make sure that we can correctly parse bigger than LONG_MAX = 2147483647 values
EXPECT_EQ(992147483647, *param_value->integer_value);
res = rcl_parse_yaml_value("lidar_ns/lidar_2", "id", "12", params);
EXPECT_TRUE(res) << rcutils_get_error_string().str;
ASSERT_TRUE(NULL != param_value->integer_value);
Expand Down

0 comments on commit 7bcc293

Please sign in to comment.