Skip to content
Snippets Groups Projects
Verified Commit 0d61f9f4 authored by Tom Almeida's avatar Tom Almeida
Browse files

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

parent da664d49
No related branches found
No related tags found
No related merge requests found
...@@ -165,6 +165,9 @@ impl FILE { ...@@ -165,6 +165,9 @@ impl FILE {
} }
impl fmt::Write for FILE { impl fmt::Write for FILE {
fn write_str(&mut self, s: &str) -> Result { fn write_str(&mut self, s: &str) -> Result {
if !self.can_write() {
return Err(Error);
}
let s = s.as_bytes(); let s = s.as_bytes();
if self.write(s) != s.len() { if self.write(s) != s.len() {
Err(Error) Err(Error)
...@@ -175,6 +178,9 @@ impl fmt::Write for FILE { ...@@ -175,6 +178,9 @@ impl fmt::Write for FILE {
} }
impl Write for FILE { impl Write for FILE {
fn write_u8(&mut self, byte: u8) -> Result { fn write_u8(&mut self, byte: u8) -> Result {
if !self.can_write() {
return Err(Error);
}
if self.write(&[byte]) != 1 { if self.write(&[byte]) != 1 {
Err(Error) Err(Error)
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment