Message ID | 20241222000509.2205895-15-hjl.tools@gmail.com |
---|---|
State | Accepted |
Commit | 799e686c88f96ec418a01917bc236efd3ed0eb18 |
Headers | show |
Series | [01/39] conform: Use -dD instead of -dN on compiler invocation | expand |
"H.J. Lu" <hjl.tools@gmail.com> writes: > From: Adhemerval Zanella <adhemerval.zanella@linaro.org> > > Clang emits the following warnings: s/lenght/length/ in title > > ../sysdeps/unix/sysv/linux/tst-getdents64.c:111:18: error: fields must > have a constant size: 'variable length array in structure' extension > will never be supported > char buffer[buffer_size]; > ^ > > Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org> > --- > sysdeps/unix/sysv/linux/tst-getdents64.c | 18 +++++++----------- > 1 file changed, 7 insertions(+), 11 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/tst-getdents64.c b/sysdeps/unix/sysv/linux/tst-getdents64.c > index ba66d49a2e..feba24d7b4 100644 > --- a/sysdeps/unix/sysv/linux/tst-getdents64.c > +++ b/sysdeps/unix/sysv/linux/tst-getdents64.c > @@ -103,6 +103,8 @@ do_test_by_size (size_t buffer_size) > int fd = xopen (".", O_RDONLY | O_DIRECTORY, 0); > TEST_VERIFY (fd >= 0); > > + char *data = xposix_memalign (_Alignof (struct dirent64), buffer_size); > + > /* Perform two passes, with a rewind operating between passes. */ > for (int pass = 0; pass < 2; ++pass) > { > @@ -111,23 +113,15 @@ do_test_by_size (size_t buffer_size) > > while (true) > { > - /* Simple way to make sure that the memcpy below does not read > - non-existing data. */ > - struct > - { > - char buffer[buffer_size]; > - struct dirent64 pad; > - } data; > - > - ssize_t ret = getdents64 (fd, &data.buffer, sizeof (data.buffer)); > + ssize_t ret = getdents64 (fd, data, buffer_size); > if (ret < 0) > FAIL_EXIT1 ("getdents64: %m"); > if (ret == 0) > break; > ++read_count; > > - char *current = data.buffer; > - char *end = data.buffer + ret; > + char *current = data; > + char *end = data + ret; > while (current != end) > { > struct dirent64 entry; > @@ -170,6 +164,8 @@ do_test_by_size (size_t buffer_size) > rewinddir (reference); > } > > + free (data); > + > xclose (fd); > closedir (reference); > }
diff --git a/sysdeps/unix/sysv/linux/tst-getdents64.c b/sysdeps/unix/sysv/linux/tst-getdents64.c index ba66d49a2e..feba24d7b4 100644 --- a/sysdeps/unix/sysv/linux/tst-getdents64.c +++ b/sysdeps/unix/sysv/linux/tst-getdents64.c @@ -103,6 +103,8 @@ do_test_by_size (size_t buffer_size) int fd = xopen (".", O_RDONLY | O_DIRECTORY, 0); TEST_VERIFY (fd >= 0); + char *data = xposix_memalign (_Alignof (struct dirent64), buffer_size); + /* Perform two passes, with a rewind operating between passes. */ for (int pass = 0; pass < 2; ++pass) { @@ -111,23 +113,15 @@ do_test_by_size (size_t buffer_size) while (true) { - /* Simple way to make sure that the memcpy below does not read - non-existing data. */ - struct - { - char buffer[buffer_size]; - struct dirent64 pad; - } data; - - ssize_t ret = getdents64 (fd, &data.buffer, sizeof (data.buffer)); + ssize_t ret = getdents64 (fd, data, buffer_size); if (ret < 0) FAIL_EXIT1 ("getdents64: %m"); if (ret == 0) break; ++read_count; - char *current = data.buffer; - char *end = data.buffer + ret; + char *current = data; + char *end = data + ret; while (current != end) { struct dirent64 entry; @@ -170,6 +164,8 @@ do_test_by_size (size_t buffer_size) rewinddir (reference); } + free (data); + xclose (fd); closedir (reference); }
From: Adhemerval Zanella <adhemerval.zanella@linaro.org> Clang emits the following warnings: ../sysdeps/unix/sysv/linux/tst-getdents64.c:111:18: error: fields must have a constant size: 'variable length array in structure' extension will never be supported char buffer[buffer_size]; ^ Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> --- sysdeps/unix/sysv/linux/tst-getdents64.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)