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.
This commit is contained in:
Daniel Eklöf 2020-10-29 18:06:04 +01:00
parent d31139515f
commit 273f105af5
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 5 additions and 2 deletions

View file

@ -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,