Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ pub mod argument {
/// need to null terminate a string to print it, you can skip that step.
String(&'a CStr),
/// `c`
Char(u8),
Char(c_char),
/// `x`
Hex(UnsignedInt),
/// `X`
Expand Down
4 changes: 2 additions & 2 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ pub fn fmt_write(w: &mut impl fmt::Write) -> impl FnMut(Argument) -> c_int + '_
},
Specifier::Char(data) => {
if flags.contains(Flags::LEFT_ALIGN) {
write!(w, "{:width$}", data as char, width = width as usize)
write!(w, "{:width$}", data as u8 as char, width = width as usize)
} else {
write!(w, "{:>width$}", data as char, width = width as usize)
write!(w, "{:>width$}", data as u8 as char, width = width as usize)
}
}
Specifier::Pointer(data) => {
Expand Down
24 changes: 19 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl Length {
unsafe fn parse_signed(self, args: &mut VaList) -> SignedInt {
match self {
Length::Int => SignedInt::Int(args.arg()),
Length::Char => SignedInt::Char(args.arg::<i32>() as i8),
Length::Short => SignedInt::Short(args.arg::<i32>() as i16),
Length::Char => SignedInt::Char(args.arg::<c_int>() as c_schar),
Length::Short => SignedInt::Short(args.arg::<c_int>() as c_short),
Length::Long => SignedInt::Long(args.arg()),
Length::LongLong => SignedInt::LongLong(args.arg()),
// for some reason, these exist as different options, yet produce the same output
Expand All @@ -85,8 +85,8 @@ impl Length {
unsafe fn parse_unsigned(self, args: &mut VaList) -> UnsignedInt {
match self {
Length::Int => UnsignedInt::Int(args.arg()),
Length::Char => UnsignedInt::Char(args.arg::<u32>() as u8),
Length::Short => UnsignedInt::Short(args.arg::<u32>() as u16),
Length::Char => UnsignedInt::Char(args.arg::<c_uint>() as c_uchar),
Length::Short => UnsignedInt::Short(args.arg::<c_uint>() as c_ushort),
Length::Long => UnsignedInt::Long(args.arg()),
Length::LongLong => UnsignedInt::LongLong(args.arg()),
// for some reason, these exist as different options, yet produce the same output
Expand Down Expand Up @@ -197,7 +197,21 @@ pub unsafe fn format(
Specifier::String(CStr::from_ptr(arg))
}
}
b'c' => Specifier::Char(args.arg::<u32>() as u8),
b'c' => {
trait CharToInt {
type IntType;
}

impl CharToInt for c_schar {
type IntType = c_int;
}

impl CharToInt for c_uchar {
type IntType = c_uint;
}

Specifier::Char(args.arg::<<c_char as CharToInt>::IntType>() as c_char)
}
b'p' => Specifier::Pointer(args.arg()),
b'n' => Specifier::WriteBytesWritten(written, args.arg()),
_ => return -1,
Expand Down