Skip to content

Commit

Permalink
Handle long longs
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 30, 2023
1 parent 5749950 commit 43a87d3
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions esp-wifi/src/compat/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(crate) unsafe fn vsnprintf(
let s = str_from_c(format);

let mut format_char = ' ';
let mut is_long = false;
let mut is_long = 0;
let mut found = false;
for c in s.chars().into_iter() {
if !found {
Expand All @@ -111,7 +111,7 @@ pub(crate) unsafe fn vsnprintf(
} else {
if c.is_numeric() || c == '-' || c == 'l' {
if c == 'l' {
is_long = true;
is_long = is_long + 1;
}
// ignore
} else {
Expand All @@ -124,19 +124,23 @@ pub(crate) unsafe fn vsnprintf(
// have to format an arg
match format_char {
'd' => {
// FIXME: This is sus - both branches have the same impl
if is_long {
if is_long < 2 {
let v = args.arg::<i32>();
write!(res_str, "{}", v).ok();
} else {
let v = args.arg::<i32>();
let v = args.arg::<i64>();
write!(res_str, "{}", v).ok();
}
}

'u' => {
let v = args.arg::<u32>();
write!(res_str, "{}", v).ok();
if is_long < 2 {
let v = args.arg::<u32>();
write!(res_str, "{}", v).ok();
} else {
let v = args.arg::<u64>();
write!(res_str, "{}", v).ok();
}
}

'p' => {
Expand All @@ -146,7 +150,7 @@ pub(crate) unsafe fn vsnprintf(

'X' => {
let v = args.arg::<u32>();
write!(res_str, "{:02x}", (v & 0xff000000) >> 24).ok();
write!(res_str, "{:02X}", v).ok();
}

'x' => {
Expand All @@ -155,7 +159,7 @@ pub(crate) unsafe fn vsnprintf(
}

's' => {
let v = args.arg::<u32>() as *const u8;
let v = args.arg::<*const u8>();
let vbuf = str_from_c(v);
res_str.append(vbuf);
}
Expand All @@ -178,7 +182,7 @@ pub(crate) unsafe fn vsnprintf(

format_char = ' ';
found = false;
is_long = false;
is_long = 0;
}
}

Expand Down

0 comments on commit 43a87d3

Please sign in to comment.