]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
util: Fix signed/unsigned comparisons by casting
authorMartin Schwenke <martin@meltin.net>
Fri, 21 Jun 2019 05:11:49 +0000 (15:11 +1000)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 1 Jul 2019 08:00:29 +0000 (08:00 +0000)
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

lib/util/msghdr.c
lib/util/pidfile.c
lib/util/sys_rw_data.c
lib/util/talloc_report.c
lib/util/util_file.c

index fec544628443dcf7a24ecffa36ac943dcd2ddfe0..3a1d6f5a017e5a85cf292fc2e4858c0a1e7dd1c4 100644 (file)
@@ -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;
index 5cd09cee75ce5d73f4dab7bba0a5f460a5eb1c86..b90ff12a8c76bf992c235f65f5dc9ad471529e58 100644 (file)
@@ -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;
        }
index de71716291c9336e964ba79e4c808a4e7025390b..a0d69f76eaf6ff9a0a7f04e24c84ebe077701568 100644 (file)
@@ -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) {
index fb12a2f631c8944afd16f86f5d8cbca7ff660c33..0aec96603b62fcb2fc543125296a6f9400f2460b 100644 (file)
@@ -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 {
index 5d92eaafdf420ea1910caa73393d4aeec5c69d24..48ee03fb5f9b4592df82f4e7a184ff3d24b03f29 100644 (file)
@@ -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;
        }