push_swap icon indicating copy to clipboard operation
push_swap copied to clipboard

Integer limit validation

Open JsExpertCoder opened this issue 4 months ago • 2 comments

First of all, thank you for sharing your work! 🙌 I’m currently studying your algorithm to better understand the push_swap project (also reading your wonderful article on Medium, and while testing your project in a GitHub Codespace I think I found a small issue in the int limit validation.

You are using ft_atoi2, which is a good choice 👍, but here’s the problem: If I pass a number that overflows the long range (the "i" variable type in ft_atoi2), the value wraps around. The wrapped value may fall inside the valid int range, so your validation assumes it’s valid — even though the real number provided by the user is actually out of range.

For example (see attached image), passing 18446744073709551658 (ULONG_MAX) results in the program treating it as 42, which is inside int limits. In this case the input should really be rejected.

Image

JsExpertCoder avatar Aug 19 '25 08:08 JsExpertCoder

Thank you to bring this up! Unfortunately, I'm not currently maintaining the repo and just keeping it around for students. If you want to contribute either to articles or repository, you are more than welcomed! By this way, you can enable the power of open source. 😄

ayogun avatar Aug 20 '25 08:08 ayogun

I'm the one who thanks!

I'll follow your advice for sure 🔥

JsExpertCoder avatar Aug 22 '25 08:08 JsExpertCoder