dnkl/foot
41
2.0k
Fork
You've already forked foot
243

render: fix nanosec "overflow" when calculating timeout value #1184

Closed
skv wants to merge 1 commit from skv/foot:timeout-nsec-overflow into master
pull from: skv/foot:timeout-nsec-overflow
merge into: dnkl:master
dnkl:master
dnkl:osc-5522
dnkl:sixel-heap-buffer-overflow
dnkl:releases/1.27
dnkl:releases/1.26
dnkl:releases/1.25
dnkl:releases/1.24
dnkl:multi-cursor
dnkl:releases/1.23
dnkl:pixman-16f-2
dnkl:releases/1.22
dnkl:releases/1.21
dnkl:releases/1.20
dnkl:releases/1.19
dnkl:releases/1.18
dnkl:releases/1.17
dnkl:releases/1.16
dnkl:releases/1.15
dnkl:releases/1.14
dnkl:releases/1.13
dnkl:releases/1.12
dnkl:releases/1.11
dnkl:releases/1.10
dnkl:releases/1.9
dnkl:releases/1.8
dnkl:releases/1.7
dnkl:releases/1.6
dnkl:releases/1.5
dnkl:releases/1.4
dnkl:releases/1.3
dnkl:releases/1.2
dnkl:releases/1.1
dnkl:releases/1.0
First-time contributor
Copy link

When resize-delay-ms >= 1000, timerfd_settime fails with EINVAL (foot output: failed to arm TIOCSWINSZ timer). This PR adds a simple fix. I also skimmed over the code and it seems that any other usage of timerfd_settime is safe.

When `resize-delay-ms >= 1000`, `timerfd_settime` fails with `EINVAL` (foot output: failed to arm TIOCSWINSZ timer). This PR adds a simple fix. I also skimmed over the code and it seems that any other usage of `timerfd_settime` is safe.
dnkl left a comment
Copy link

Thanks! See note below. In addition to that, I'd like to see a changelog entry for this.

Thanks! See note below. In addition to that, I'd like to see a changelog entry for this.
render.c Outdated
@ -3722,0 +3722,4 @@
if (timeout.it_value.tv_nsec >= 1000000000) {
timeout.it_value.tv_sec += timeout.it_value.tv_nsec / 1000000000;
timeout.it_value.tv_nsec %= 1000000000;
}
Owner
Copy link

We can do better than this: just calculate tv_sec and tv_nsec directly:

diff --git a/render.c b/render.c
index b285b120..f14911d4 100644
--- a/render.c
+++ b/render.c
@@ -3716,7 +3716,10 @@ send_dimensions_to_client(struct terminal *term)
 if (fd >= 0) {
 /* Reset timeout */
 const struct itimerspec timeout = {
- .it_value = {.tv_sec = 0, .tv_nsec = delay_ms * 1000000},
+ .it_value = {
+ .tv_sec = delay_ms / 1000,
+ .tv_nsec = (delay_ms % 1000) * 1000000,
+ },
 };
 
 if (timerfd_settime(fd, 0, &timeout, NULL) < 0) {
We can do better than this: just calculate `tv_sec` and `tv_nsec` directly: ```diff diff --git a/render.c b/render.c index b285b120..f14911d4 100644 --- a/render.c +++ b/render.c @@ -3716,7 +3716,10 @@ send_dimensions_to_client(struct terminal *term) if (fd >= 0) { /* Reset timeout */ const struct itimerspec timeout = { - .it_value = {.tv_sec = 0, .tv_nsec = delay_ms * 1000000}, + .it_value = { + .tv_sec = delay_ms / 1000, + .tv_nsec = (delay_ms % 1000) * 1000000, + }, }; if (timerfd_settime(fd, 0, &timeout, NULL) < 0) { ```
dnkl marked this conversation as resolved
skv force-pushed timeout-nsec-overflow from bc9d8829f1
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
to b1e2167655
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2022年10月05日 16:01:34 +02:00
Compare
skv 2022年10月05日 16:04:01 +02:00
  • closed this pull request
  • requested review from dnkl
Author
First-time contributor
Copy link

Thanks! See note below. In addition to that, I'd like to see a changelog entry for this.

Done!

> Thanks! See note below. In addition to that, I'd like to see a changelog entry for this. Done!
skv reopened this pull request 2022年10月05日 16:17:08 +02:00
Author
First-time contributor
Copy link

@dnkl Sorry, I must have accidentally closed this PR somehow, though I do not how.

@dnkl Sorry, I must have accidentally closed this PR somehow, though I do not how.
Owner
Copy link

Awesome, thanks! Merged in 37218be648

Awesome, thanks! Merged in 37218be64853dccd5574a7f5de7193c0e1a7b5e6
dnkl closed this pull request 2022年10月05日 16:53:33 +02:00
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot!1184
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "skv/foot:timeout-nsec-overflow"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?