Browse Source

Make sure we can actually write before writing anything when using printf

Tom Almeida 6 years ago
parent
commit
0d61f9f4fd
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/stdio/src/lib.rs

+ 6 - 0
src/stdio/src/lib.rs

@@ -165,6 +165,9 @@ impl FILE {
 }
 impl fmt::Write for FILE {
     fn write_str(&mut self, s: &str) -> Result {
+        if !self.can_write() {
+            return Err(Error);
+        }
         let s = s.as_bytes();
         if self.write(s) != s.len() {
             Err(Error)
@@ -175,6 +178,9 @@ impl fmt::Write for FILE {
 }
 impl Write for FILE {
     fn write_u8(&mut self, byte: u8) -> Result {
+        if !self.can_write() {
+            return Err(Error);
+        }
         if self.write(&[byte]) != 1 {
             Err(Error)
         } else {