Skip to content

Printing / Formatting f64 crashes #136

@bjoernQ

Description

@bjoernQ

This code

#![no_std]
#![no_main]

use esp32_hal::{clock::ClockControl, pac::Peripherals, prelude::*, timer::TimerGroup, RtcCntl};
use esp_backtrace as _;
use esp_println::println;
use xtensa_lx_rt::entry;

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take().unwrap();
    let system = peripherals.DPORT.split();
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    // Disable the RTC and TIMG watchdog timers
    let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
    let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
    let mut wdt0 = timer_group0.wdt;
    let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
    let mut wdt1 = timer_group1.wdt;

    rtc_cntl.set_wdt_global_enable(false);
    wdt0.disable();
    wdt1.disable();

    println!("Howdy!");

    let foo = 3.14f32;
    println!("{}", foo * 2f32);

    let foo = 3.14f64;
    println!("{}", foo * 2f64);

    loop {

    }
}

works correct for debug builds on ESP32 but crashes for release builds like this:

Howdy!
6.28


!! A panic occured in 'C:\Users\Bjoern\.rustup\toolchains\esp\lib\rustlib\src\rust\library\core\src\num\flt2dec\mod.rs', at line 189, column 5

PanicInfo {
    payload: Any { .. },
    message: Some(
        assertion failed: buf[0] > b\'0\',
    ),
    location: Location {
        file: "C:\\Users\\Bjoern\\.rustup\\toolchains\\esp\\lib\\rustlib\\src\\rust\\library\\core\\src\\num\\flt2dec\\mod.rs",
        line: 189,
        col: 5,
    },
    can_unwind: true,
}

Backtrace:

0x400d7e8e
0x400d7e8e - _ZN4core3num7flt2dec17digits_to_dec_str17heb592f82a70d05d1E
    at ??:??
0x400d82e1
0x400d82e1 - _ZN4core3num7flt2dec15to_shortest_str17hb3626511ee59378eE
    at ??:??
0x400d6960
0x400d6960 - _ZN4core3fmt5float32float_to_decimal_common_shortest17hfff5f366670e650eE.llvm.14292657683144325728
    at ??:??
0x400d69cf
0x400d69cf - _ZN4core3fmt5float52_$LT$impl$u20$core..fmt..Display$u20$for$u20$f64$GT$3fmt17h0efd241b8f8506e7E
    at ??:??
0x400d6b12
0x400d6b12 - _ZN4core3fmt5write17hfeac229cab89db3fE
    at ??:??
0x400d08fc
0x400d08fc - main
    at ??:??
0x400d0b5a
0x400d0b5a - Reset
    at ??:??
0x400d0a98
0x400d0a98 - ESP32Reset
    at ??:??

This happens on the current (1.63.0.2) version and at least a few older ones

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions