cmds: fix integer conversions

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2021-09-27 12:04:34 +02:00
parent 69f5d68a5c
commit 98775a4cc9
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D
2 changed files with 12 additions and 8 deletions

View File

@ -111,11 +111,11 @@ static char *get_username(void)
__do_free char *buf = NULL;
struct passwd pwent;
struct passwd *pwentp = NULL;
size_t bufsize;
ssize_t bufsize;
int ret;
bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
if (bufsize == -1)
if (bufsize < 0)
bufsize = 1024;
buf = malloc(bufsize);
@ -144,7 +144,7 @@ static char **get_groupnames(void)
int ret, i;
struct group grent;
struct group *grentp = NULL;
size_t bufsize;
ssize_t bufsize;
ngroups = getgroups(0, NULL);
if (ngroups < 0) {
@ -174,7 +174,7 @@ static char **get_groupnames(void)
}
bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
if (bufsize == -1)
if (bufsize < 0)
bufsize = 1024;
buf = malloc(bufsize);
@ -659,6 +659,7 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid,
size_t length = 0;
int ret;
size_t slen;
ssize_t nbytes;
char *owner;
char nicname[IFNAMSIZ];
struct alloted_s *n;
@ -755,7 +756,8 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid,
return NULL;
}
if (lxc_pwrite_nointr(fd, newline, slen, length) != slen) {
nbytes = lxc_pwrite_nointr(fd, newline, slen, length);
if (nbytes < 0 || (size_t)nbytes != slen) {
CMD_SYSERROR("Failed to append new entry \"%s\" to database file", newline);
if (lxc_netdev_delete_by_name(nicname) != 0)

View File

@ -228,13 +228,13 @@ static int read_default_map(char *fnam, int which, char *user)
static int find_default_map(void)
{
__do_free char *buf = NULL;
size_t bufsize;
ssize_t bufsize;
struct passwd pwent;
int ret = -1;
struct passwd *pwentp = NULL;
bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
if (bufsize == -1)
if (bufsize < 0)
bufsize = 1024;
buf = malloc(bufsize);
@ -261,12 +261,14 @@ static int find_default_map(void)
return 0;
}
static bool is_in_ns_range(long id, struct id_map *map)
static bool is_in_ns_range(unsigned long id, struct id_map *map)
{
if (id < map->nsid)
return false;
if (id >= map->nsid + map->range)
return false;
return true;
}