@@ -1268,27 +1268,26 @@ extern "C" WEAK void __cxa_pure_virtual(void)
12681268extern uint32_t __mbed_sbrk_start;
12691269extern uint32_t __mbed_krbs_start;
12701270/* Additional RAM memory used for heap - please note this
1271- * address should be lower address then the previous default address
1271+ * address must be lower address then the previous default address
12721272 */
12731273extern uint32_t __mbed_sbrk_start_0;
12741274extern uint32_t __mbed_krbs_start_0;
12751275
12761276extern " C" WEAK caddr_t _sbrk (int incr)
12771277{
12781278 static uint32_t heap = (uint32_t ) &__mbed_sbrk_start_0;
1279- static bool once = true ;
12801279 uint32_t prev_heap = heap;
12811280 uint32_t new_heap = heap + incr;
12821281
12831282 /* *
1284- * If the new address is outside the first region, start allocating from the second region.
1285- * Jump to second region is done just once, and `static bool once` is used to keep track of that.
1283+ * If we exceed the first region, start allocating from the second region.
12861284 */
1287- if (once && (new_heap > (uint32_t ) &__mbed_krbs_start_0)) {
1288- once = false ;
1285+ if (prev_heap <= (uint32_t ) &__mbed_krbs_start_0 && new_heap > (uint32_t ) &__mbed_krbs_start_0) {
12891286 prev_heap = (uint32_t ) &__mbed_sbrk_start;
12901287 new_heap = prev_heap + incr;
1291- } else if (new_heap > (uint32_t ) &__mbed_krbs_start) {
1288+ }
1289+
1290+ if (new_heap > (uint32_t ) &__mbed_krbs_start) {
12921291 /* *
12931292 * If the new address is outside the second region, return out-of-memory.
12941293 */
0 commit comments