From 7de6565722b09362fdd2fc8c9d6f3e6eb6aacea4 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Thu, 13 Oct 2022 10:03:33 +0200 Subject: [PATCH] heap: fix comment and return condition in heap_caps_check_add_region_allowed() (See cd805a5ab1c8299ab931edf40777fcc7912bd6ca) --- components/heap/heap_caps_init.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/heap/heap_caps_init.c b/components/heap/heap_caps_init.c index 2b532b6e2a..2a513f4619 100644 --- a/components/heap/heap_caps_init.c +++ b/components/heap/heap_caps_init.c @@ -170,13 +170,13 @@ esp_err_t heap_caps_add_region(intptr_t start, intptr_t end) bool heap_caps_check_add_region_allowed(intptr_t heap_start, intptr_t heap_end, intptr_t start, intptr_t end) { /* - * We assume that in any region, the "start" must be stictly less than the end. + * We assume that in any region, the "start" must be strictly less than the end. * Specially, the 3rd scenario can be allowed. For example, allocate memory from heap, * then change the capability and call this function to create a new region for special * application. * This 'start = start' and 'end = end' scenario is incorrect because the same region - * cannot be add twice. For example, add the .bss memory to region twice, if not do the - * check, it will cause exception. + * cannot be added twice. In fact, registering the same memory region as a heap twice + * would cause a corruption and then an exception at runtime. * * the existing heap region s(tart) e(nd) * |----------------------| @@ -201,7 +201,7 @@ bool heap_caps_check_add_region_allowed(intptr_t heap_start, intptr_t heap_end, bool condition_4 = start < heap_end && end > heap_end; // if true then region not allowed bool condition_6 = start == heap_start && end == heap_end; // if true then region not allowed - return (condition_2 || condition_4 || condition_6) ? false: true; + return !(condition_2 || condition_4 || condition_6); } esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end)