Skip to content

calloc memory data is not initialized to zero for MINIMAL_LIBC #9221

@pswarnak

Description

@pswarnak

As per calloc description, the allocated memory is set to zero.
In the current MINIMAL_LIBC implementation of calloc in Zephyr, calloc memory data is not initialized to zero.

Arch: all
Board: all

Code Snippet:
void test_calloc(void)
{
char *cptr = NULL;
cptr = (char *) calloc(CALLOC_BUFLEN, sizeof(char));
zassert_not_null((cptr), "calloc failed, errno: %d", errno);
zassert_true(((memcmp((char *)cptr, zerobuf, CALLOC_BUFLEN)) == 0),
"calloc failed to set zero value);
free(cptr);
cptr = NULL;
}

Error Console Log:

starting test - test_calloc

    Assertion failed at zephyr/tests/lib/mem_alloc/src/main.c:67: test_calloc: (((memcmp((char *)cptr, zerobuf, CALLOC_BUFLEN)) == 0) is false)
calloc failed to set zero value
FAIL - test_calloc

Steps to reproduce:

Just run the code snippet on any supported target.
cd zephyr/tests/crypto/ecc_dsa/
rm -rf build && mkdir build && cd build
cmake -D BOARD=qemu_x86 ../
make run

Check the console log.

Additional Information:
calloc_zephyr_implementation does not explicitly call memset to set data in allocated memory to zero.

Metadata

Metadata

Assignees

Labels

area: C LibraryC Standard LibrarybugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions