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.
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
skv
commented 2022年10月03日 19:40:05 +02:00
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
requested changes 2022年10月04日 21:21:10 +02:00
dnkl
left a comment
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;
}
dnkl
commented 2022年10月04日 21:20:40 +02:00
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
to
2022年10月05日 16:01:34 +02:00
Compare
bc9d8829f1
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
b1e2167655
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
skv
2022年10月05日 16:04:01 +02:00
- closed this pull request
- requested review from dnkl
skv
commented 2022年10月05日 16:05:09 +02:00
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
skv
commented 2022年10月05日 16:17:29 +02:00
@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.
dnkl
commented 2022年10月05日 16:53:33 +02:00
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
Labels
Clear labels
bug
Something is not working
compositor
Compositor bug
doc
Documentation
duplicate
This issue or pull request already exists
easy
enhancement
New feature
help wanted
Need some help
invalid
Something is wrong
not-a-bug
performance
question
More information is needed
refactor
regression
upstream
Issue needs to be fixed upstream
what do you think?
Looking for opinions
wiki
Issue or patch for the wiki
wontfix
This won't be fixed
No labels
bug
compositor
doc
duplicate
easy
enhancement
help wanted
invalid
not-a-bug
performance
question
refactor
regression
upstream
what do you think?
wiki
wontfix
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
Loading...
Add table
Add a link
Reference in a new issue
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?