Skip to content

equeue: Fix overflow in rtos-less timeout code #7782

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

Merged
merged 1 commit into from
Aug 16, 2018

Conversation

geky
Copy link
Contributor

@geky geky commented Aug 14, 2018

Description

See #7732

Thanks to @simonnilsson
CC @cmonr, @pan-

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Feature
[ ] Breaking change

@@ -154,7 +154,7 @@ bool equeue_sema_wait(equeue_sema_t *s, int ms) {
if (ms == 0) {
return false;
} else if (ms > 0) {
timeout.attach_us(callback(equeue_sema_timeout, s), ms*1000);
timeout.attach_us(callback(equeue_sema_timeout, s), (us_timestamp_t)ms*1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be (us_timestamp_t)(ms * 1000) ?

Copy link
Member

Choose a reason for hiding this comment

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

Why would it be ? result of the expression (ms * 1000) is int which means it is already truncated if it has overflowed.
We want to promote either ms or 1000 to make the calculation happen in the us_timestamp_t number system.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, we can cast ms to us first and then do the multiplication, though I think what i suggested is clearer to the intention but I don't care that much tbh :)

Copy link
Member

Choose a reason for hiding this comment

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

I must be missing something but what you suggested is very different and produce different result; see here

@adbridge adbridge requested a review from pan- August 14, 2018 11:29
@adbridge
Copy link
Contributor

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

Build : ABORTED

Build number : 2808
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7782/

@cmonr
Copy link
Contributor

cmonr commented Aug 14, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

Build : SUCCESS

Build number : 2812
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7782/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 16, 2018

@cmonr cmonr merged commit 7927823 into master Aug 16, 2018
pan- pushed a commit to pan-/mbed that referenced this pull request Aug 22, 2018
…imeout-overflow

equeue: Fix overflow in rtos-less timeout code
@cmonr cmonr deleted the g-equeue-fix-rtos-less-timeout-overflow branch September 26, 2018 15:24
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.

6 participants