Skip to content

Commit

Permalink
platforms: nuttx: SerialImpl: fix poll timeout and integer underflow (#…
Browse files Browse the repository at this point in the history
…23248)

* platforms: nuttx: SerialImpl: fix poll timeout

* platforms: posix: SerialImpl: fix poll timeout
  • Loading branch information
dakejahl authored Jun 15, 2024
1 parent 4fe0bb4 commit fcb479c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions platforms/nuttx/src/px4/common/SerialImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ ssize_t SerialImpl::readAtLeast(uint8_t *buffer, size_t buffer_size, size_t char
fds[0].fd = _serial_fd;
fds[0].events = POLLIN;

hrt_abstime remaining_time = timeout_us - hrt_elapsed_time(&start_time_us);
hrt_abstime elapsed_time_us = hrt_elapsed_time(&start_time_us);

if (remaining_time <= 0) { break; }
if (elapsed_time_us > timeout_us) { break; }

int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), remaining_time);
int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), (timeout_us - elapsed_time_us) / 1000);

if (ret > 0) {
if (fds[0].revents & POLLIN) {
Expand Down
6 changes: 3 additions & 3 deletions platforms/posix/src/px4/common/SerialImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ ssize_t SerialImpl::readAtLeast(uint8_t *buffer, size_t buffer_size, size_t char
fds[0].fd = _serial_fd;
fds[0].events = POLLIN;

hrt_abstime remaining_time = timeout_us - hrt_elapsed_time(&start_time_us);
hrt_abstime elapsed_time_us = hrt_elapsed_time(&start_time_us);

if (remaining_time <= 0) { break; }
if (elapsed_time_us > timeout_us) { break; }

int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), remaining_time);
int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), (timeout_us - elapsed_time_us) / 1000);

if (ret > 0) {
if (fds[0].revents & POLLIN) {
Expand Down

0 comments on commit fcb479c

Please sign in to comment.