From 06fa5817489adb9728f8a29d4cb7602fb48b8bdb Mon Sep 17 00:00:00 2001 From: Yuriy M. Kaminskiy Date: Sat, 27 Feb 2016 19:27:29 +0300 Subject: misc: safer (and uniform) handling of return value When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow. Signed-off-by: Karel Zak --- term-utils/agetty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'term-utils/agetty.c') diff --git a/term-utils/agetty.c b/term-utils/agetty.c index d88cdc1c0..55a00e125 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -1001,8 +1001,8 @@ static void open_tty(char *tty, struct termios *tp, struct options *op) if ((gr = getgrnam("tty"))) gid = gr->gr_gid; - if (((len = snprintf(buf, sizeof(buf), "/dev/%s", tty)) >= - (int)sizeof(buf)) || (len < 0)) + len = snprintf(buf, sizeof(buf), "/dev/%s", tty); + if (len < 0 || (size_t)len >= sizeof(buf)) log_err(_("/dev/%s: cannot open as standard input: %m"), tty); /* Open the tty as standard input. */ -- cgit v1.2.3-55-g7522