mirror of https://github.com/ARMmbed/mbed-os.git
Prevent underflow in heap size calculation
If the free memory on a device is small enough then the calculation to determine heap size could underflow to a large value. If this happens then malloc will never return failure and instead will cause a crash on allocation. This patch prevents the underflow so malloc works as expected even with low amounts of free memory.pull/3898/head
parent
b2726470f6
commit
88f879d0f8
|
@ -478,7 +478,7 @@ void set_stack_heap(void) {
|
|||
mbed_stack_isr_start = ISR_STACK_START;
|
||||
#else
|
||||
/* Interrupt stack - reserve space at the end of the free block */
|
||||
mbed_stack_isr_size = ISR_STACK_SIZE;
|
||||
mbed_stack_isr_size = ISR_STACK_SIZE < free_size ? ISR_STACK_SIZE : free_size;
|
||||
mbed_stack_isr_start = free_start + free_size - mbed_stack_isr_size;
|
||||
free_size -= mbed_stack_isr_size;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue