From: Lennart Poettering Date: Fri, 21 Jun 2024 07:41:43 +0000 (+0200) Subject: tree-wide: fix type of read() return variable at a couple of places X-Git-Tag: v257-rc1~1075 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18eaff4272f3276282d4c1629e06b502142de1f0;p=thirdparty%2Fsystemd.git tree-wide: fix type of read() return variable at a couple of places read() returns ssize_t (i.e. 64bit typically). We assigned it to int variables in some cases (i.e. 32bit typically). Let's not be so sloppy, and not accidentally drop 32bit on the floor. (of course, this is not an issue IRL since we'll not have allocations above 2^32 ever we could read into, but still, let's clean this up) --- diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index 79ff4f81167..49492330e2f 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -791,7 +791,8 @@ int parse_elf_object(int fd, const char *executable, bool fork_disable_dump, cha NULL); if (r < 0) { if (r == -EPROTO) { /* We should have the errno from the child, but don't clobber original error */ - int e, k; + ssize_t k; + int e; k = read(error_pipe[0], &e, sizeof(e)); if (k < 0 && errno != EAGAIN) /* Pipe is non-blocking, EAGAIN means there's nothing */ diff --git a/src/shared/journal-importer.c b/src/shared/journal-importer.c index bb0536e48af..4dc0b8f662a 100644 --- a/src/shared/journal-importer.c +++ b/src/shared/journal-importer.c @@ -127,7 +127,7 @@ static int fill_fixed_size(JournalImporter *imp, void **data, size_t size) { assert(data); while (imp->filled - imp->offset < size) { - int n; + ssize_t n; if (imp->passive_fd) /* we have to wait for some data to come to us */ diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 7b16cf2258b..928afefe713 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -293,7 +293,7 @@ TEST(copy_tree_at_symlink) { TEST_RET(copy_bytes) { _cleanup_close_pair_ int pipefd[2] = EBADF_PAIR; _cleanup_close_ int infd = -EBADF; - int r, r2; + int r; char buf[1024], buf2[1024]; infd = open("/usr/lib/os-release", O_RDONLY|O_CLOEXEC); @@ -307,14 +307,14 @@ TEST_RET(copy_bytes) { r = copy_bytes(infd, pipefd[1], UINT64_MAX, 0); assert_se(r == 0); - r = read(pipefd[0], buf, sizeof(buf)); - assert_se(r >= 0); + ssize_t n = read(pipefd[0], buf, sizeof(buf)); + assert_se(n >= 0); assert_se(lseek(infd, 0, SEEK_SET) == 0); - r2 = read(infd, buf2, sizeof(buf2)); - assert_se(r == r2); + ssize_t n2 = read(infd, buf2, sizeof(buf2)); + assert_se(n == n2); - assert_se(strneq(buf, buf2, r)); + assert_se(strneq(buf, buf2, n)); /* test copy_bytes with invalid descriptors */ r = copy_bytes(pipefd[0], pipefd[0], 1, 0); diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index 8f0f6e701c4..516bddefbe6 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -253,9 +253,9 @@ TEST(passfd_read) { assert_se(receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAIT, &fd) == 0); assert_se(fd >= 0); - r = read(fd, buf, sizeof(buf)-1); - assert_se(r >= 0); - buf[r] = 0; + ssize_t n = read(fd, buf, sizeof(buf)-1); + assert_se(n >= 0); + buf[n] = 0; ASSERT_STREQ(buf, file_contents); }