Loading...
 
Skip to main content

System Workbench for STM32


sprintf call causes STM32L4xx to crash

STM32 crashes when using the sprintf function

1. Software environment: Keil MDK 5.15
2. Hardware environment: STM32F103C8T6 minimum system
Today, when I was programming STM32, I made a strange mistake. The program was blocked in a function. After looking it up for a long time, I found that it was blocked in the sprintf function!!
Serial port printed the first sentence, the card died, the next sentence did not execute to.



The reasons are as follows

__''void foo(char *path)
{
...
printu("enter dir:%s\r\n", path);
sprintf(path + i, "/%s", fn);
printu("enter1 dir:%s\r\n", path);
...

}

call foo("0:");''__



The access to the path array is out of bounds! When calling, write as follows:

__''char path10 ="0:";
foo(path);''__