Threads using sprintf with float
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
New
|
Undecided
|
Unassigned |
Bug Description
OS: CMSIS RTX
GCC ARM: 4.9 2015q3
Libs: nosys
Linker: --specs=nano.specs -u _printf_float
Hi,
I have faced and issue when using sprintf with floats. I have 2 threads using sprintf a number and after a while it will hardfault.
Sbrk will return if there is no heap left and malloc is guarded with a mutex. It seems to free a non valid address and then corrution begins. It apparently fails only with floats.
This is how you can replicate it.
void function_
sprintf(
sprintf(
}
void test_var_
char str[128];
char value[32];
float number = 0;
printf(" \n thread 1 \n");
while(1) {
for (uint32_t i = 0; i < 200; i++){
function_
number++;
}
osDelay(10);
}
}
void test_var_
char str[128];
char value[32];
float number = 0;
printf(" \n thread 2 \n");
while(1) {
for (uint32_t i = 0; i < 200; i++){
function_
number++;
}
osDelay(10);
}
}
osThreadDef (test_var_string_1, osPriorityLow, 1, 0);
osThreadDef (test_var_string_2, osPriorityLow, 1, 0);
void main(void){
osThreadCreate (osThread(
osThreadCreate (osThread(
for(;;){
osDelay(100);
}
}
newlib-nano is not thread safe. It is recommended to use newlib instead in your case.