]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: fix type of read() return variable at a couple of places
authorLennart Poettering <lennart@poettering.net>
Fri, 21 Jun 2024 07:41:43 +0000 (09:41 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 22 Jun 2024 08:05:36 +0000 (17:05 +0900)
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)

src/shared/elf-util.c
src/shared/journal-importer.c
src/test/test-copy.c
src/test/test-socket-util.c

index 79ff4f811676b9c3621d4a0491c001bfbad05795..49492330e2f5c4e7760c009eed7338ebdde1a96e 100644 (file)
@@ -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 */
index bb0536e48af81c9e15c7b125e45f022c64a93fb2..4dc0b8f662a8bf7bef05db2f76e4a412c9774342 100644 (file)
@@ -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 */
index 7b16cf2258b025ede3eb9640a4a4c07c0131d3be..928afefe71392b613723731a763a48875cd205ff 100644 (file)
@@ -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);
index 8f0f6e701c495ba7d27076a7453f4efd6095f032..516bddefbe6f46f6595302215d7f59cf22ed566c 100644 (file)
@@ -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);
 }