From 273f105af5861e35f58b6a37e9b1b576dd9adaec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 29 Oct 2020 18:06:04 +0100 Subject: [PATCH] tiocswinsz: fix compilation error on e.g. ppc64 On some platforms, TIOCSWINSZ has a very large value, > 0x80000000. On some platforms, the `request` argument to `ioctl(3)` is an `int`. For platforms where both of the above is true, gcc will warn (and error out if compiled with `-Werror`) on: ioctl(fd, TIOCSWINSZ, ...) To silence this warning, we need to cast `TIOCSWINSZ` to an integer. However, doing this on platforms where `request` is an `unsigned long` will result in `TIOCSWINSZ` being sign-extended (and thus we end up with an invalid value). It seems that casting to `unsigned int` works in both cases; it silences the long -> int conversion warning, while also preserving the correct value in all cases. --- CHANGELOG.md | 3 +++ render.c | 2 +- terminal.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c0d03aa..02cab39e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ * XCursor shape in CSD corners when window is tiled. * Error handling when processing keyboard input (maybe https://codeberg.org/dnkl/foot/issues/171). +* Compilation error _"overflow in conversion from long 'unsigned int' + to 'int' changes value... "_ seen on platforms where the `request` + argument in `ioctl(3)` is an `int` (for example: linux/ppc64). ## 1.5.2 diff --git a/render.c b/render.c index 819a249b..bad3e218 100644 --- a/render.c +++ b/render.c @@ -2174,7 +2174,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->margins.left, term->margins.right, term->margins.top, term->margins.bottom); /* Signal TIOCSWINSZ */ - if (term->ptmx >= 0 && ioctl(term->ptmx, TIOCSWINSZ, + if (term->ptmx >= 0 && ioctl(term->ptmx, (unsigned int)TIOCSWINSZ, &(struct winsize){ .ws_row = term->rows, .ws_col = term->cols, diff --git a/terminal.c b/terminal.c index f931ba7d..4651fc1a 100644 --- a/terminal.c +++ b/terminal.c @@ -883,7 +883,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, goto close_fds; } - if (ioctl(ptmx, TIOCSWINSZ, + if (ioctl(ptmx, (unsigned int)TIOCSWINSZ, &(struct winsize){.ws_row = 24, .ws_col = 80}) < 0) { LOG_ERRNO("failed to set initial TIOCSWINSZ");