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

BUG: Integer underflow causes HUGE space() in sendGeneric() #381

Merged
merged 1 commit into from
Dec 22, 2017

Conversation

crankyoldgit
Copy link
Owner

A mesgtime of zero (or less than the elapsed time to send a message) tickled
a bug in sendGeneric() due to the subtraction of two unsigned values.

This bug isn't catchable with our current unit test setup.
This was discovered by "on hardware" testing.

FYI @roidayan That elegant solution wasn't so elegant after all.

A mesgtime of zero (or less than the elapsed time to send a message) tickled
a bug in `sendGeneric()` due to the subtraction of two unsigned values resulting in a negative number.

This bug isn't catchable with our current unit test setup.
This was discovered by "on hardware" testing.
@crankyoldgit
Copy link
Owner Author

I'm submitting this as is, as it is rather a show-stopping bug. I don't want to leave master broken for too long.

@crankyoldgit crankyoldgit merged commit ac06877 into master Dec 22, 2017
@crankyoldgit crankyoldgit deleted the fix_sendgeneric branch December 29, 2017 06:13
if (elapsed >= mesgtime)
space(gap);
else
space(std::max(gap, mesgtime - elapsed));
Copy link
Collaborator

Choose a reason for hiding this comment

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

you still avoid duplicating the rest of the function so i think its worth it.
if you don't like the if statement another way is using one line if statement like this:

uint32_t space_gap = elapsed > mesgtime ? gap : std::max(gap, mesgtime - elapsed);
space(space_gap);

Copy link
Owner Author

Choose a reason for hiding this comment

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

Agreed. No doubt the de-duplication of the procedure was worth it. Just the road to heck is/was paved with good intentions. ;-)

I don't think changing the code to the one-liner actually saves any compiled code/space. The compiler should do that the optimal anyway. If it does save space, I'll change it. However I think the code is more readable to others with a if statement verses the conditional assignment.

@roidayan
Copy link
Collaborator

roidayan commented Jan 2, 2018 via email

crankyoldgit added a commit that referenced this pull request Jan 25, 2018
Since `sendJVC()` was updated to use `sendGeneric()` it has produced a double
minimum gap at the end of each message, instead of a single one.
This wasn't picked up by our unit-testing.
This tickled a situation where an integer underflow happened when calculating
the required `space()` length, which would cause a delay of approx 1h20m.
Refactored code to eliminate this problem, and a potential similar case
in `sendWhynter()` too.

This is a derivative of the bug/issue #381

This instance was reported in #400, which this patch should fix.
crankyoldgit added a commit that referenced this pull request Jan 26, 2018
Since `sendJVC()` was updated to use `sendGeneric()` it has produced a double
minimum gap at the end of each message, instead of a single one.
This wasn't picked up by our unit-testing.
This tickled a situation where an integer underflow happened when calculating
the required `space()` length, which would cause a delay of approx 1h20m.
Refactored code to eliminate this problem, and a potential similar case
in `sendWhynter()` too.

This is a derivative of the bug/issue #381

This instance was reported in #400, which this patch should fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants