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 timeout calculation #1

Open
terrillmoore opened this issue Mar 21, 2022 · 0 comments
Open

Fix timeout calculation #1

terrillmoore opened this issue Mar 21, 2022 · 0 comments
Assignees
Labels

Comments

@terrillmoore
Copy link
Member

Timeout calculation has a signed compare problem.

unsigned long now = millis();
while(!isConversionAvailable(deviceAddress) && (millis() - delms < now));

millis() - delms is unsigned (because now is unsigned and both sides of the < are promoted). At a rollover interval, this can exit too soon. The correct calculation is:

(millis() - now) < (unsigned) delms

The result of millis() - now is always the right number of elapsed milliseconds, regardless of rollover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant