add stack overflow protection

This commit is contained in:
Jorge Aparicio
2020-09-07 19:09:36 +02:00
parent b2cfe52694
commit 25eb06c089
2 changed files with 26 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
#![no_main]
#![no_std]
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
ack(10, 10);
{{crate_name}}::exit()
}
fn ack(m: u32, n: u32) -> u32 {
defmt::info!("ack(m={:u32}, n={:u32})", m, n);
let mut big = [2; 512];
if m == 0 {
n + 1
} else {
big[100] += 1;
if n == 0 {
ack(m - 1, 1)
} else {
ack(m - 1, ack(m, n - 1))
}
}
}