summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-05-06 14:31:06 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-05-06 14:51:35 +0100
commitaa8bdfee1db818b9a56908ab0197ff02c54bf281 (patch)
treeb146de66f6ef7f5ed91fdac9477cadaf46b67e46 /libstdc++-v3
parentlibstdc++: Do not include <cxxabi.h> in <stacktrace> (diff)
downloadgcc-aa8bdfee1db818b9a56908ab0197ff02c54bf281.tar.gz
gcc-aa8bdfee1db818b9a56908ab0197ff02c54bf281.tar.bz2
gcc-aa8bdfee1db818b9a56908ab0197ff02c54bf281.tar.xz
libstdc++: Fix test that fails on Solaris [PR104731]
On Solaris the dirent::d_name member is a single char, causing this test to fail with warnings about buffer overflow. Change the test to use a union with additional space for writing a string to the d_name member. libstdc++-v3/ChangeLog: PR libstdc++/104731 * testsuite/27_io/filesystem/iterators/error_reporting.cc: Use a trailing char array as storage for dirent::d_name.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc35
1 files changed, 22 insertions, 13 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc
index 1f297a731a3..1c8ea4c9249 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc
@@ -28,35 +28,44 @@
28 28
29int choice; 29int choice;
30 30
31struct dirent global_dirent;
32
33extern "C" struct dirent* readdir(DIR*) 31extern "C" struct dirent* readdir(DIR*)
34{ 32{
33 // On some targets dirent::d_name is very small, but the OS allocates
34 // a trailing char array after the dirent struct. Emulate that here.
35 union State
36 {
37 struct dirent d;
38 char buf[sizeof(struct dirent) + 16] = {};
39 };
40
41 static State state;
42 char* d_name = state.buf + offsetof(struct dirent, d_name);
43
35 switch (choice) 44 switch (choice)
36 { 45 {
37 case 1: 46 case 1:
38 global_dirent.d_ino = 999; 47 state.d.d_ino = 999;
39#if defined _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE && defined DT_REG 48#if defined _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE && defined DT_REG
40 global_dirent.d_type = DT_REG; 49 state.d.d_type = DT_REG;
41#endif 50#endif
42 global_dirent.d_reclen = 0; 51 state.d.d_reclen = 0;
43 std::char_traits<char>::copy(global_dirent.d_name, "file", 5); 52 std::char_traits<char>::copy(d_name, "file", 5);
44 choice = 0; 53 choice = 0;
45 return &global_dirent; 54 return &state.d;
46 case 2: 55 case 2:
47 global_dirent.d_ino = 111; 56 state.d.d_ino = 111;
48#if defined _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE && defined DT_DIR 57#if defined _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE && defined DT_DIR
49 global_dirent.d_type = DT_DIR; 58 state.d.d_type = DT_DIR;
50#endif 59#endif
51 global_dirent.d_reclen = 60; 60 state.d.d_reclen = 60;
52 std::char_traits<char>::copy(global_dirent.d_name, "subdir", 7); 61 std::char_traits<char>::copy(d_name, "subdir", 7);
53 choice = 1; 62 choice = 1;
54 return &global_dirent; 63 return &state.d;
55 default: 64 default:
56 errno = EIO; 65 errno = EIO;
57 return nullptr; 66 return nullptr;
58 } 67 }
59 return &global_dirent; 68 return &state.d;
60} 69}
61 70
62void 71void