Skip to content

Commit 38fefd7

Browse files
committed
Remove slicing ub
1 parent d5fd9ed commit 38fefd7

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

include/tmp/file

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <ios>
88
#include <istream>
99

10+
#ifdef __GLIBCXX__
11+
#include <ext/stdio_filebuf.h>
12+
#endif
13+
1014
namespace tmp {
1115

1216
/// tmp::file is a smart handle that manages a temporary file, ensuring
@@ -85,10 +89,15 @@ public:
8589

8690
private:
8791
/// The underlying C file stream
88-
std::unique_ptr<std::FILE, decltype(&std::fclose)> underlying;
92+
std::unique_ptr<std::FILE, int(*)(std::FILE*)> underlying;
8993

94+
#ifdef __GLIBCXX__
95+
/// The underlying raw file device object
96+
mutable __gnu_cxx::stdio_filebuf<char> sb;
97+
#else
9098
/// The underlying raw file device object
9199
std::filebuf sb;
100+
#endif
92101
};
93102
} // namespace tmp
94103

src/file.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ file::file(std::ios::openmode mode)
217217
#elif defined(_LIBCPP_VERSION)
218218
sb.__open(fileno(underlying.get()), mode);
219219
#else
220-
static_assert(sizeof(std::filebuf) == sizeof(__gnu_cxx::stdio_filebuf<char>));
221220
sb = __gnu_cxx::stdio_filebuf<char>(underlying.get(), mode);
222221
#endif
223222

0 commit comments

Comments
 (0)