terminal: fix integer comparisons

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2021-09-03 11:41:25 +02:00
parent 652a1f4ba5
commit 8703bf5bdb
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -270,7 +270,7 @@ static int lxc_terminal_write_log_file(struct lxc_terminal *terminal, char *buf,
if (ret < 0)
return ret;
if (bytes_read <= terminal->log_size)
if ((uint64_t)bytes_read <= terminal->log_size)
return lxc_write_nointr(terminal->log_fd, buf, bytes_read);
/* Write as much as we can into the buffer and loose the rest. */
@ -301,7 +301,7 @@ static int lxc_terminal_write_log_file(struct lxc_terminal *terminal, char *buf,
if (ret < 0)
return ret;
if (terminal->log_size < bytes_read) {
if (terminal->log_size < (uint64_t)bytes_read) {
/* Well, this is unfortunate because it means that there is more
* to write than the user has granted us space. There are
* multiple ways to handle this but let's use the simplest one:
@ -615,7 +615,7 @@ on_error:
int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
{
int ttynum;
size_t ttynum;
int ptxfd = -1;
struct lxc_tty_info *ttys = &conf->ttys;
struct lxc_terminal *terminal = &conf->console;
@ -632,7 +632,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
}
if (*ttyreq > 0) {
if (*ttyreq > ttys->max)
if ((size_t)*ttyreq > ttys->max)
goto out;
if (ttys->tty[*ttyreq - 1].busy >= 0)
@ -652,7 +652,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
if (ttynum > ttys->max)
goto out;
*ttyreq = ttynum;
*ttyreq = (int)ttynum;
out_tty:
ttys->tty[ttynum - 1].busy = sockfd;
@ -664,11 +664,10 @@ out:
void lxc_terminal_free(struct lxc_conf *conf, int fd)
{
int i;
struct lxc_tty_info *ttys = &conf->ttys;
struct lxc_terminal *terminal = &conf->console;
for (i = 0; i < ttys->max; i++)
for (size_t i = 0; i < ttys->max; i++)
if (ttys->tty[i].busy == fd)
ttys->tty[i].busy = -1;