diff --git a/components/heap/heap_caps_init.c b/components/heap/heap_caps_init.c index 1a7aca3ded..6b770650c2 100644 --- a/components/heap/heap_caps_init.c +++ b/components/heap/heap_caps_init.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "heap_private.h" #include #include @@ -180,28 +172,38 @@ esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, //Check if region overlaps the start and/or end of an existing region. If so, the //region is invalid (or maybe added twice) /* - * assume that in on region, start must be less than end (cannot equal to) !! - * Specially, the 4th scenario can be allowed. For example, allocate memory from heap, + * We assume that in any region, the "start" must be stictly 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. - * In the following chart, 'start = start' and 'end = end' is contained in 3rd scenario. + * In the following chart, 'start = start' and 'end = end' is contained in 4th scenario. * This all equal 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. * * the existing heap region s(tart) e(nd) * |----------------------| - * 1.add region [Correct] (s1start; + * + * 2.add region (s2=s) |-----------------| wrong: bool condition_2 = start < heap->start && end >= heap->start; + * |---------------------------------| wrong + * + * 3.add region (s3>=s && e3= heap->start && end < heap->end; + * |--------------| correct + * + * 4.add region (s4=e) |----------------------| wrong: bool condition_4 = start < heap->end && end >= heap->end; + * |---------------------| wrong + * + * 5.add region (s5>=e) |----| correct: bool condition_5 = start >= heap->end; */ heap_t *heap; SLIST_FOREACH(heap, ®istered_heaps, next) { - if ((start <= heap->start && end > heap->start) - || (start < heap->end && end > heap->end)) { + bool condition_2 = start < heap->start && end >= heap->start; //if 1, wrong + bool condition_4 = start < heap->end && end >= heap->end; //if 1, wrong + bool wrong_region = condition_2 || condition_4; + + if (wrong_region) { return ESP_FAIL; } } diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 67eb57061f..591c3e56fd 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -986,7 +986,6 @@ components/hal/twai_hal_iram.c components/hal/uart_hal.c components/hal/uart_hal_iram.c components/hal/usb_hal.c -components/heap/heap_caps_init.c components/heap/heap_private.h components/heap/heap_task_info.c components/heap/heap_tlsf.c