ATCA_NO_HEAP does not cover the custom-HAL allocation in hal_iface_init()
Affected versions
v3.8.0 (d49c7d5)
Configuration
Bare-metal target (no heap), built with:
-DATCA_NO_HEAP=ON -DATCA_HAL_CUSTOM=ON
Problem
With ATCA_NO_HEAP defined, the library is documented (and annotated) to perform no
dynamic memory allocation. However, hal_iface_init() (lib/hal/atca_hal.c) allocates the custom-HAL
function-pointer struct unconditionally when ATCA_CUSTOM_IFACE is used
(lib/hal/atca_hal.c:306-308, v3.8.0):
#ifdefATCA_HAL_CUSTOMif (ATCA_CUSTOM_IFACE==cfg->iface_type)
{
*hal=hal_malloc(sizeof(ATCAHAL_t)); /* not gated by ATCA_NO_HEAP */
Observed behaviour
On a heapless target (malloc returns NULL), atcab_init() with a
custom-HAL ATCAIfaceCfg fails with ATCA_ALLOC_FAILURE.
Expected behaviour
With ATCA_NO_HEAP defined, no code path calls hal_malloc/hal_free.
Suggested fix
When using ATCA_NO_HEAP, use a static ATCAHAL_t instance in hal_iface_init() .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ATCA_NO_HEAP does not cover the custom-HAL allocation in hal_iface_init()
Affected versions
Configuration
Bare-metal target (no heap), built with:
Problem
With ATCA_NO_HEAP defined, the library is documented (and annotated) to perform no
dynamic memory allocation. However, hal_iface_init() (lib/hal/atca_hal.c) allocates the custom-HAL
function-pointer struct unconditionally when ATCA_CUSTOM_IFACE is used
(lib/hal/atca_hal.c:306-308, v3.8.0):
Observed behaviour
On a heapless target (malloc returns NULL), atcab_init() with a
custom-HAL ATCAIfaceCfg fails with ATCA_ALLOC_FAILURE.
Expected behaviour
With ATCA_NO_HEAP defined, no code path calls hal_malloc/hal_free.
Suggested fix
When using ATCA_NO_HEAP, use a static ATCAHAL_t instance in hal_iface_init() .