File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1549,7 +1549,8 @@ template <typename F> class glibc_file : public file_base<F> {
15491549 bool needs_flush () const {
15501550 if ((this ->file_ ->_flags & line_buffered) == 0 ) return false ;
15511551 char * end = this ->file_ ->_IO_write_end ;
1552- return memchr (end, ' \n ' , to_unsigned (this ->file_ ->_IO_write_ptr - end));
1552+ return memchr (end, ' \n ' ,
1553+ max_of<ptrdiff_t >(this ->file_ ->_IO_write_ptr - end, 0 ));
15531554 }
15541555
15551556 void flush () { fflush_unlocked (this ->file_ ); }
Original file line number Diff line number Diff line change @@ -2549,6 +2549,20 @@ TEST(format_test, writer) {
25492549 EXPECT_EQ (s.str (), " foo" );
25502550}
25512551
2552+ #if FMT_USE_FCNTL
2553+ TEST (format_test, invalid_glibc_buffer) {
2554+ auto pipe = fmt::pipe ();
2555+ auto write_end = pipe.write_end .fdopen (" w" );
2556+ auto file = write_end.get ();
2557+
2558+ // This results in _IO_write_ptr < _IO_write_end.
2559+ fprintf (file, " 111\n " );
2560+ setvbuf (file, nullptr , _IOLBF, 0 );
2561+
2562+ fmt::print (file, " ------\n " );
2563+ }
2564+ #endif // FMT_USE_FCNTL
2565+
25522566#if FMT_USE_BITINT
25532567FMT_PRAGMA_CLANG (diagnostic ignored " -Wbit-int-extension" )
25542568
You can’t perform that action at this time.
0 commit comments