Skip to content

Commit

Permalink
Handle errors consistently in vsprintf and vsnprintf. (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Dec 29, 2023
1 parent f787ba5 commit 2513047
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions c-scape/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@ unsafe extern "C" fn vsprintf(

let mut out = String::new();
let num_bytes = format(fmt, va_list, output::fmt_write(&mut out));
if num_bytes < 0 {
return num_bytes;
}
debug_assert_eq!(out.len(), num_bytes as usize);

let copy_len = num_bytes as usize + 1;
Expand Down Expand Up @@ -758,6 +761,9 @@ unsafe extern "C" fn vsnprintf(

let mut out = String::new();
let num_bytes = format(fmt, va_list, output::fmt_write(&mut out));
if num_bytes < 0 {
return num_bytes;
}
debug_assert_eq!(out.len(), num_bytes as usize);

let copy_len = min(num_bytes as usize + 1, len);
Expand Down Expand Up @@ -787,6 +793,7 @@ unsafe extern "C" fn vdprintf(fd: c_int, fmt: *const c_char, va_list: VaList<'_,
if num_bytes < 0 {
return num_bytes;
}
debug_assert_eq!(out.len(), num_bytes as usize);

let bytes = out.into_bytes();
let mut remaining = &bytes[..];
Expand Down

0 comments on commit 2513047

Please sign in to comment.