#Does anyone know why the `format!()` macro would cause a crash
61 messages · Page 1 of 1 (latest)
does format!("Hello") crash?
Yes
.
hmmmm
and i assume this is a segfault
or something
"crash" is very not specific
what's the error?
I assume some CPU exception happens
well, can you run it in a debugger and see which one?
It's kind of hard to debug because my code is running in vmx root
actually yeah maybe
also you've not declared your own format macro right
serial.write_str(&String::from("asdf\n"));
you're using the stdlib one
ok
this works
serial.write_str(&format!("asdf\n"));
it's possible the stack is corrupted
?expand
format!("Hello")
{
let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(&["Hello"], &[]));
res
}
hmmm
maybe split it up into 2 parts
once doing format_args!("Hello")
the other doing a to_string() on that
see where it crashes?
format_args! works
that's interesting
it's crashing in to_string
let buf = [0u8; 0x500];
for i in buf {
if i != 0 {
serial.write_str("bad\n");
}
}
this works fine so i assume it's not an issue with the stack
args.as_str() works
?expand
format_args!("hello")
::core::fmt::Arguments::new_v1(&["hello"], &[])
@vestal tapir Found the issue
if args.pieces.len() != args.args.len() {
serial.write_str("3\n");
}
Ok I don't know if anyone is still reading this but this is the weirdest issue ever
I found the issue is in the Write::write_str method
If I put this function inside core/fmt/mod.rs it crashes
But if I put it in my lib.rs it doesn't crash
This works
This crashes
An explanation for this last thing would be the usage of a fmt::Write impl vs a io::Write one, maybe
Regarding the initial question, have you checked that your realloc logic is fine. And also make sure you're not recursing into string formatting inside the alloc logic
I’m using the bump allocator
Yeah I think that’s it
They're both using fmt::Write
Looks like it's an issue with the trait object
It works if I use static dispatch