mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
util: Fix signed/unsigned comparisons by casting
One case needs a variable declared, so it can be compared to -1 and then cast to size_t for comparison. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Mon Jul 1 08:00:29 UTC 2019 on sn-devel-184
This commit is contained in:
parent
115353a001
commit
043334f2eb
@ -223,7 +223,7 @@ ssize_t msghdr_copy(struct msghdr_buf *msg, size_t msgsize,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bufsize >= fd_len) {
|
if (bufsize >= (size_t)fd_len) {
|
||||||
bufsize -= fd_len;
|
bufsize -= fd_len;
|
||||||
} else {
|
} else {
|
||||||
bufsize = 0;
|
bufsize = 0;
|
||||||
@ -256,7 +256,7 @@ ssize_t msghdr_copy(struct msghdr_buf *msg, size_t msgsize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
needed = offsetof(struct msghdr_buf, buf) + fd_len;
|
needed = offsetof(struct msghdr_buf, buf) + fd_len;
|
||||||
if (needed < fd_len) {
|
if (needed < (size_t)fd_len) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
needed += iov_len;
|
needed += iov_len;
|
||||||
|
@ -82,7 +82,7 @@ int pidfile_path_create(const char *path, int *outfd)
|
|||||||
ret = errno;
|
ret = errno;
|
||||||
goto fail_unlink;
|
goto fail_unlink;
|
||||||
}
|
}
|
||||||
if (len >= sizeof(tmp)) {
|
if ((size_t)len >= sizeof(tmp)) {
|
||||||
ret = ENOSPC;
|
ret = ENOSPC;
|
||||||
goto fail_unlink;
|
goto fail_unlink;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
|
|||||||
memcpy(iov_copy, orig_iov, sizeof(struct iovec) * iovcnt);
|
memcpy(iov_copy, orig_iov, sizeof(struct iovec) * iovcnt);
|
||||||
iov = iov_copy;
|
iov = iov_copy;
|
||||||
|
|
||||||
while (sent < to_send) {
|
while (sent < (size_t)to_send) {
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
ok = iov_advance(&iov, &iovcnt, thistime);
|
ok = iov_advance(&iov, &iovcnt, thistime);
|
||||||
@ -104,7 +104,7 @@ ssize_t read_data(int fd, void *buffer, size_t n)
|
|||||||
|
|
||||||
nread = 0;
|
nread = 0;
|
||||||
|
|
||||||
while (nread < n) {
|
while ((size_t)nread < n) {
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
ret = sys_read(fd, ((char *)buffer) + nread, n - nread);
|
ret = sys_read(fd, ((char *)buffer) + nread, n - nread);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
|
@ -49,7 +49,7 @@ static char *talloc_vasprintf_append_largebuf(char *buf, ssize_t *pstr_len,
|
|||||||
}
|
}
|
||||||
buflen = talloc_get_size(buf);
|
buflen = talloc_get_size(buf);
|
||||||
|
|
||||||
if (buflen > str_len) {
|
if (buflen > (size_t)str_len) {
|
||||||
start = buf + str_len;
|
start = buf + str_len;
|
||||||
space = buflen - str_len;
|
space = buflen - str_len;
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,7 +74,7 @@ _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint)
|
|||||||
|
|
||||||
offset += ret;
|
offset += ret;
|
||||||
|
|
||||||
} while (ret == hint);
|
} while ((size_t)ret == hint);
|
||||||
|
|
||||||
data[offset] = '\0';
|
data[offset] = '\0';
|
||||||
|
|
||||||
@ -327,12 +327,14 @@ _PUBLIC_ char **fd_lines_load(int fd, int *numlines, size_t maxsize, TALLOC_CTX
|
|||||||
_PUBLIC_ bool file_save_mode(const char *fname, const void *packet,
|
_PUBLIC_ bool file_save_mode(const char *fname, const void *packet,
|
||||||
size_t length, mode_t mode)
|
size_t length, mode_t mode)
|
||||||
{
|
{
|
||||||
|
ssize_t num_written;
|
||||||
int fd;
|
int fd;
|
||||||
fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, mode);
|
fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, mode);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (write(fd, packet, length) != (size_t)length) {
|
num_written = write(fd, packet, length);
|
||||||
|
if (num_written == -1 || (size_t)num_written != length) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user