diff --git a/dirent.c b/dirent.c index ae576c82..de5a163d 100644 --- a/dirent.c +++ b/dirent.c @@ -83,9 +83,12 @@ SYS_FUNC(getdents) tprints(", "); return 0; } + + const unsigned int count = tcp->u_arg[2]; + if (syserror(tcp) || !verbose(tcp)) { printaddr(tcp->u_arg[1]); - tprintf(", %lu", tcp->u_arg[2]); + tprintf(", %u", count); return 0; } @@ -101,7 +104,7 @@ SYS_FUNC(getdents) buf = malloc(len); if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) { printaddr(tcp->u_arg[1]); - tprintf(", %lu", tcp->u_arg[2]); + tprintf(", %u", count); free(buf); return 0; } @@ -150,7 +153,7 @@ SYS_FUNC(getdents) tprints("]"); else tprintf("/* %u entries */", dents); - tprintf(", %lu", tcp->u_arg[2]); + tprintf(", %u", count); free(buf); return 0; } diff --git a/dirent64.c b/dirent64.c index 3c90a258..448a2f1a 100644 --- a/dirent64.c +++ b/dirent64.c @@ -49,9 +49,12 @@ SYS_FUNC(getdents64) tprints(", "); return 0; } + + const unsigned int count = tcp->u_arg[2]; + if (syserror(tcp) || !verbose(tcp)) { printaddr(tcp->u_arg[1]); - tprintf(", %lu", tcp->u_arg[2]); + tprintf(", %u", count); return 0; } @@ -67,7 +70,7 @@ SYS_FUNC(getdents64) buf = malloc(len); if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) { printaddr(tcp->u_arg[1]); - tprintf(", %lu", tcp->u_arg[2]); + tprintf(", %u", count); free(buf); return 0; } @@ -117,7 +120,7 @@ SYS_FUNC(getdents64) tprints("]"); else tprintf("/* %u entries */", dents); - tprintf(", %lu", tcp->u_arg[2]); + tprintf(", %u", count); free(buf); return 0; } diff --git a/tests/getdents.c b/tests/getdents.c index 16541df6..7ea2067f 100644 --- a/tests/getdents.c +++ b/tests/getdents.c @@ -96,7 +96,6 @@ int main(int ac, const char **av) { char *dname; - int rc; assert(ac == 1); assert(asprintf(&dname, "%s.test.tmp.dir", av[0]) > 0); @@ -106,9 +105,16 @@ main(int ac, const char **av) assert(!creat(fname, 0600)); assert(!close(0)); assert(!open(".", O_RDONLY | O_DIRECTORY)); - while ((rc = syscall(__NR_getdents, 0, buf, sizeof(buf)))) { + + unsigned long count = (unsigned long) 0xfacefeeddeadbeef; + long rc = syscall(__NR_getdents, (long) 0xdefacedffffffff, NULL, count); + printf("getdents(-1, NULL, %u) = %ld %s (%m)\n", + (unsigned) count, rc, errno2name()); + + count = (unsigned long) 0xfacefeed00000000 | sizeof(buf); + while ((rc = syscall(__NR_getdents, 0, buf, count))) { kernel_dirent *d; - int i; + long i; if (rc < 0) perror_msg_and_skip("getdents"); @@ -119,9 +125,9 @@ main(int ac, const char **av) printf(", "); print_dirent(d); } - printf("], %zu) = %d\n", sizeof(buf), rc); + printf("], %u) = %ld\n", (unsigned) count, rc); } - printf("getdents(0, [], %zu) = 0\n", sizeof(buf)); + printf("getdents(0, [], %u) = 0\n", (unsigned) count); puts("+++ exited with 0 +++"); assert(!unlink(fname)); assert(!chdir("..")); diff --git a/tests/getdents64.c b/tests/getdents64.c index 7077d9c7..54149d21 100644 --- a/tests/getdents64.c +++ b/tests/getdents64.c @@ -101,7 +101,6 @@ int main(int ac, const char **av) { char *dname; - int rc; assert(ac == 1); assert(asprintf(&dname, "%s.test.tmp.dir", av[0]) > 0); @@ -111,9 +110,16 @@ main(int ac, const char **av) assert(!creat(fname, 0600)); assert(!close(0)); assert(!open(".", O_RDONLY | O_DIRECTORY)); - while ((rc = syscall(__NR_getdents64, 0, buf, sizeof(buf)))) { + + unsigned long count = (unsigned long) 0xfacefeeddeadbeef; + long rc = syscall(__NR_getdents64, (long) 0xdefacedffffffff, NULL, count); + printf("getdents64(-1, NULL, %u) = %ld %s (%m)\n", + (unsigned) count, rc, errno2name()); + + count = (unsigned long) 0xfacefeed00000000 | sizeof(buf); + while ((rc = syscall(__NR_getdents64, 0, buf, count))) { kernel_dirent64 *d; - int i; + long i; if (rc < 0) perror_msg_and_skip("getdents64"); @@ -124,9 +130,9 @@ main(int ac, const char **av) printf(", "); print_dirent(d); } - printf("], %zu) = %d\n", sizeof(buf), rc); + printf("], %u) = %ld\n", (unsigned) count, rc); } - printf("getdents64(0, [], %zu) = 0\n", sizeof(buf)); + printf("getdents64(0, [], %u) = 0\n", (unsigned) count); puts("+++ exited with 0 +++"); assert(!unlink(fname)); assert(!chdir(".."));