33// For the full copyright and license information, please view the LICENSE-*
44// files that was distributed with this source code.
55
6- use crate :: utils:: format_failure_to_read_input_file;
6+ use crate :: utils:: { format_failure_to_read_input_file, format_io_error } ;
77use std:: env:: { self , ArgsOs } ;
88use std:: ffi:: OsString ;
99use std:: io:: { BufRead , BufReader , BufWriter , Read , Write } ;
@@ -441,7 +441,7 @@ pub fn cmp(params: &Params) -> Result<Cmp, String> {
441441 } ) ?;
442442 output. clear ( ) ;
443443 } else {
444- report_difference ( from_byte, to_byte, at_byte, at_line, params) ;
444+ report_difference ( from_byte, to_byte, at_byte, at_line, params) ? ;
445445 return Ok ( Cmp :: Different ) ;
446446 }
447447 }
@@ -707,9 +707,15 @@ fn is_posix_locale() -> bool {
707707}
708708
709709#[ inline]
710- fn report_difference ( from_byte : u8 , to_byte : u8 , at_byte : usize , at_line : usize , params : & Params ) {
710+ fn report_difference (
711+ from_byte : u8 ,
712+ to_byte : u8 ,
713+ at_byte : usize ,
714+ at_line : usize ,
715+ params : & Params ,
716+ ) -> Result < ( ) , String > {
711717 if params. quiet {
712- return ;
718+ return Ok ( ( ) ) ;
713719 }
714720
715721 let term = if is_posix_locale ( ) && !params. print_bytes {
@@ -734,7 +740,16 @@ fn report_difference(from_byte: u8, to_byte: u8, at_byte: usize, at_line: usize,
734740 format_visible_byte( to_byte)
735741 ) ;
736742 }
737- println ! ( ) ;
743+ // Instead of println!(), which panics in case of error (> /dev/full).
744+ let mut stdout = io:: stdout ( ) ;
745+ if let Err ( e) = writeln ! ( stdout) {
746+ return Err ( format_io_error ( & e) ) ;
747+ } ;
748+ if let Err ( e) = stdout. flush ( ) {
749+ return Err ( format_io_error ( & e) ) ;
750+ } ;
751+
752+ Ok ( ( ) )
738753}
739754
740755#[ cfg( test) ]
0 commit comments