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

unit_tests: fix strtoul unit test #9214

Merged
merged 1 commit into from Mar 8, 2024

Conversation

jeffro256
Copy link
Contributor

errno not guaranteed to be anything according to C standard, except on range error

@iamamyth
Copy link

iamamyth commented Mar 6, 2024

errno not guaranteed to be anything according to C standard, except on range error

That's exactly why the test sets errno. C functions which interact with errno change it when an error occurs (per the man page), and otherwise leave it alone; it would be ridiculous to expect functions to document what they don't do.

EXPECT_EQ(0, ul);
EXPECT_EQ(p + 1, endp);

p = " \t 0";
endp = nullptr;
ul = std::strtoul(p, const_cast<char**>(&endp), 10);
EXPECT_EQ(0, errno);
EXPECT_EQ(0, ul);
EXPECT_EQ(p + 9, endp);

p = "q";
Copy link

Choose a reason for hiding this comment

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

This part of the test would be the most likely to break across systems: Per the man page, some systems report EINVAL here: "EINVAL (not in C99) The given base contains an unsupported value." The c++ function makes no mention of EINVAL, so perhaps whoever wrote this test suite wanted a way to determine the actual behavior in a given build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you meant to put this comment on the test immediately below this one, yeah? According to the C standard, strtoul should skip over whitespace. But yes, I agree with the general point, so I updated the commit to just remove the EXPECT_EQ(0) from the invalid character test.

Copy link
Collaborator

@selsta selsta left a comment

Choose a reason for hiding this comment

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

Fixes this test failing on macOS

@luigi1111 luigi1111 merged commit 4b25580 into monero-project:master Mar 8, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants