From: Martin Schwenke Date: Fri, 21 Jun 2019 05:11:49 +0000 (+1000) Subject: util: Fix signed/unsigned comparisons by casting X-Git-Tag: ldb-2.0.5~126 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=043334f2eb67ec82c3c6b757fef5eb986d58ad25;p=thirdparty%2Fsamba.git 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 Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Mon Jul 1 08:00:29 UTC 2019 on sn-devel-184 --- diff --git a/lib/util/msghdr.c b/lib/util/msghdr.c index fec54462844..3a1d6f5a017 100644 --- a/lib/util/msghdr.c +++ b/lib/util/msghdr.c @@ -223,7 +223,7 @@ ssize_t msghdr_copy(struct msghdr_buf *msg, size_t msgsize, return -1; } - if (bufsize >= fd_len) { + if (bufsize >= (size_t)fd_len) { bufsize -= fd_len; } else { 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; - if (needed < fd_len) { + if (needed < (size_t)fd_len) { return -1; } needed += iov_len; diff --git a/lib/util/pidfile.c b/lib/util/pidfile.c index 5cd09cee75c..b90ff12a8c7 100644 --- a/lib/util/pidfile.c +++ b/lib/util/pidfile.c @@ -82,7 +82,7 @@ int pidfile_path_create(const char *path, int *outfd) ret = errno; goto fail_unlink; } - if (len >= sizeof(tmp)) { + if ((size_t)len >= sizeof(tmp)) { ret = ENOSPC; goto fail_unlink; } diff --git a/lib/util/sys_rw_data.c b/lib/util/sys_rw_data.c index de71716291c..a0d69f76eaf 100644 --- a/lib/util/sys_rw_data.c +++ b/lib/util/sys_rw_data.c @@ -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); iov = iov_copy; - while (sent < to_send) { + while (sent < (size_t)to_send) { bool ok; ok = iov_advance(&iov, &iovcnt, thistime); @@ -104,7 +104,7 @@ ssize_t read_data(int fd, void *buffer, size_t n) nread = 0; - while (nread < n) { + while ((size_t)nread < n) { ssize_t ret; ret = sys_read(fd, ((char *)buffer) + nread, n - nread); if (ret <= 0) { diff --git a/lib/util/talloc_report.c b/lib/util/talloc_report.c index fb12a2f631c..0aec96603b6 100644 --- a/lib/util/talloc_report.c +++ b/lib/util/talloc_report.c @@ -49,7 +49,7 @@ static char *talloc_vasprintf_append_largebuf(char *buf, ssize_t *pstr_len, } buflen = talloc_get_size(buf); - if (buflen > str_len) { + if (buflen > (size_t)str_len) { start = buf + str_len; space = buflen - str_len; } else { diff --git a/lib/util/util_file.c b/lib/util/util_file.c index 5d92eaafdf4..48ee03fb5f9 100644 --- a/lib/util/util_file.c +++ b/lib/util/util_file.c @@ -74,7 +74,7 @@ _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) offset += ret; - } while (ret == hint); + } while ((size_t)ret == hint); 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, size_t length, mode_t mode) { + ssize_t num_written; int fd; fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, mode); if (fd == -1) { 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); return false; }