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

[bugfix] rounding exception #36

Merged

Conversation

oceanofthelost
Copy link
Contributor

@oceanofthelost oceanofthelost commented Jan 15, 2023

Fixes a potential floating point bug (Issue #35) caused by invalid user input.

PR adds three new tests, one per input flag. IN addition, added a check in get_number.cc which checks if user has passed a zero to one of the rounding functions. If zero passed, then fatal_error() is executed and stops execution of user program.

@oceanofthelost oceanofthelost changed the title Bugfix/rounding exception [bugfix] rounding exception Jan 16, 2023
test/02/t0262a.sh Outdated Show resolved Hide resolved
test/02/t0262a.sh Show resolved Hide resolved
srecord/arglex/tool/get_number.cc Outdated Show resolved Hide resolved
Copy link
Contributor Author

@oceanofthelost oceanofthelost left a comment

Choose a reason for hiding this comment

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

Addressed all PR feedback

value /= multiple;
value *= multiple;
break;

case token_round_up:
token_next();
multiple = get_number("-round-up");
if(multiple == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add space between if and (

value = (value + multiple - 1) / multiple;
value *= multiple;
break;

case token_round_nearest:
token_next();
multiple = get_number("-round-nearest");
if(multiple == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add space between if and (

value = (value + multiple - 1) / multiple;
value *= multiple;
break;

case token_round_nearest:
token_next();
multiple = get_number("-round-nearest");
if(multiple == 0)
{
fatal_error ("-Round_Nearest value must not be 0");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove space between fatal_error and (

value /= multiple;
value *= multiple;
break;

case token_round_up:
token_next();
multiple = get_number("-round-up");
if(multiple == 0)
{
fatal_error ("-Round_Up value must not be 0");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove space between fatal_error and (

test/02/t0262a.sh Show resolved Hide resolved
test/02/t0262a.sh Outdated Show resolved Hide resolved
@oceanofthelost
Copy link
Contributor Author

Still getting used to GH PR process, BB and GL are my primary GIT web interfaces to use. How GH does things is a bit different than I am used to.

@jtxa
Copy link
Contributor

jtxa commented Jan 16, 2023

I'm also new to GH. I'm missing to reply to a specific comment (as in GL) instead of posting at the end.

@jtxa
Copy link
Contributor

jtxa commented Jan 16, 2023

About the MegaLinter issues:

  • The ShellCheck and cSpell issues are unrelated and will be fixed by CI fix #33
  • The shlfmt issues are related to the new test scripts. Looks like the continued line needs 2 more spaces for indentation.

@sierrafoxtrot
Copy link
Owner

@oceanofthelost, I've merged #32 from @jtxa (which should encompass #33). If you rebase that should take care of the megalinter checks failing . Thank you both!

Three tests added, one for each rounding method, which will fail when
providing input causing exception.
@oceanofthelost oceanofthelost force-pushed the bugfix/rounding-exception branch from f94c955 to 2e86337 Compare January 22, 2023 17:36
@sierrafoxtrot
Copy link
Owner

So close! If you can add your name and github username to doc/dictionaries/names.txt, all should be well. I should have picked that one up earlier. I'm putting together some updates with a getting started guide for new contributors and will definitely add this in there.

@marcows
Copy link
Contributor

marcows commented Jan 23, 2023

name and github username to doc/dictionaries/names.txt

Oh, my username is listed there as well, didn't know before.
What is it used for?

@sierrafoxtrot
Copy link
Owner

name and github username to doc/dictionaries/names.txt

Oh, my username is listed there as well, didn't know before. What is it used for?

@jtxa added a handy list of project-custom words for cspell which runs as part of the MegaLinter checks. This resulted ina monumental number of typos being fixed. Actually, really nice! But yeah, things like names/handles and technical terms like EPROM and even SRecord itself now get accepted gracefully. He even added all the names for contributors so that doc files don't get rejected.

@marcows
Copy link
Contributor

marcows commented Jan 23, 2023

OK, I wondered how my username landed in the SRecord sources, but now I searched and found it in doc/etc/new.1.65.so. So now the use is clear.

@jtxa
Copy link
Contributor

jtxa commented Jan 24, 2023

@sierrafoxtrot
Last year you asked about squashing PR or not. This is a good example to talk about.

This is my opinion:

The extra commits of @oceanofthelost were perfect for reviewing, it can make the process easier. But for the long term history the extra commits are irrelevant in my opinion. Who want to see that there were spelling, formatting or other problems on code, that were never used by anyone yet.

In case of a small feature I would squash it to 1 commit, the test are directly related to the implementation.
For a bugfix like this, the initial 2 commits are the perfect granularity. First commit provides a test case, where you can reproduce the bug (when you checkout that commit), the second commit fixes the bug.

If value provided by user for rounding is 0, trigger fatal error
signaling 0 is not valid input.
@oceanofthelost oceanofthelost force-pushed the bugfix/rounding-exception branch from 40986a3 to 87d1fd9 Compare January 24, 2023 05:35
@sierrafoxtrot
Copy link
Owner

@sierrafoxtrot Last year you asked about squashing PR or not. This is a good example to talk about.

This is my opinion:

The extra commits of @oceanofthelost were perfect for reviewing, it can make the process easier. But for the long term history the extra commits are irrelevant in my opinion. Who want to see that there were spelling, formatting or other problems on code, that were never used by anyone yet.

In case of a small feature I would squash it to 1 commit, the test are directly related to the implementation. For a bugfix like this, the initial 2 commits are the perfect granularity. First commit provides a test case, where you can reproduce the bug (when you checkout that commit), the second commit fixes the bug.

Thanks @jtxa , that make s lot of sense. Clean but preserves the history and effort. I like the approach.

Thanks @oceanofthelost for the contribution! This should unlock auto-run for workflows as well (which I can imagine was pretty frustrating)

@sierrafoxtrot sierrafoxtrot reopened this Jan 24, 2023
@sierrafoxtrot sierrafoxtrot merged commit eafec3c into sierrafoxtrot:master Jan 24, 2023
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.

4 participants