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

Fix for incorrect integer value conversion on Windows #1126

Merged
merged 2 commits into from Dec 21, 2023

Conversation

MichaelOrlov
Copy link
Contributor

RCA

It turns out that we are using ival = strtol(value, &endptr, 0); function when trying to parse integer value.
On Linux and 64-bit, it works correctly for values bigger than LONG_MAX = 2147483647 because sizeof(long) returns
8 bytes. However on Windows, it is not true and sizeof(long) is 4 bytes and strtol(value, &endptr, 0) can't parse values bigger than 2147483647 and we fallback to the parsing value as a floating point value with strtod(..) and it succeeds.

FIX

  1. Replaced strtol(..) with strtoll(..)
  2. Adjust values in the unit test to cover this use-case.

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

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small change, this otherwise looks good to me.

rcl_yaml_param_parser/src/parse.c Outdated Show resolved Hide resolved
Co-authored-by: Chris Lalancette <clalancette@gmail.com>

Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me with green CI.

@MichaelOrlov
Copy link
Contributor Author

Gist: https://gist.githubusercontent.com/MichaelOrlov/2b6b58cb449fe2da0a220b18bca964cd/raw/df8f73acff15d43f9ecad2ac4c5d1920b013a47a/ros2.repos
BUILD args: --packages-above-and-dependencies rcl_yaml_param_parser
TEST args: --packages-above rcl_yaml_param_parser
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/13038

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, @MichaelOrlov thanks!

@fujitatomoya
Copy link
Collaborator

Note

we would want to backport this to iron and humble.

@clalancette clalancette merged commit 7bcc293 into ros2:rolling Dec 21, 2023
2 of 3 checks passed
@clalancette
Copy link
Contributor

@Mergifyio backport humble iron

Copy link

mergify bot commented Dec 21, 2023

backport humble iron

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Dec 21, 2023
* Fix for incorrect integer value conversion on Windows

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

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
(cherry picked from commit 7bcc293)
mergify bot pushed a commit that referenced this pull request Dec 21, 2023
* Fix for incorrect integer value conversion on Windows

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

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
(cherry picked from commit 7bcc293)
clalancette pushed a commit that referenced this pull request Jan 4, 2024
* Fix for incorrect integer value conversion on Windows

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

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
(cherry picked from commit 7bcc293)

Co-authored-by: Michael Orlov <morlovmr@gmail.com>
clalancette pushed a commit that referenced this pull request Jan 4, 2024
* Fix for incorrect integer value conversion on Windows

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

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
(cherry picked from commit 7bcc293)

Co-authored-by: Michael Orlov <morlovmr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rcl_yaml_param_parser incorrectly parsing integer values bigger than LONG_MAX = 2147483647
3 participants