@@ -1268,27 +1268,26 @@ extern "C" WEAK void __cxa_pure_virtual(void)
1268
1268
extern uint32_t __mbed_sbrk_start;
1269
1269
extern uint32_t __mbed_krbs_start;
1270
1270
/* 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
1272
1272
*/
1273
1273
extern uint32_t __mbed_sbrk_start_0;
1274
1274
extern uint32_t __mbed_krbs_start_0;
1275
1275
1276
1276
extern " C" WEAK caddr_t _sbrk (int incr)
1277
1277
{
1278
1278
static uint32_t heap = (uint32_t ) &__mbed_sbrk_start_0;
1279
- static bool once = true ;
1280
1279
uint32_t prev_heap = heap;
1281
1280
uint32_t new_heap = heap + incr;
1282
1281
1283
1282
/* *
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.
1286
1284
*/
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) {
1289
1286
prev_heap = (uint32_t ) &__mbed_sbrk_start;
1290
1287
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) {
1292
1291
/* *
1293
1292
* If the new address is outside the second region, return out-of-memory.
1294
1293
*/
0 commit comments