【rp2_common】【pico_malloc.c】Modify the code to check if rc is a null pointer before calling rc #1397

Closed
opened 2023-05-26 22:51:38 -05:00 by jming912 · 3 comments
jming912 commented 2023-05-26 22:51:38 -05:00 (Migrated from github.com)
The code on lines 41, 58, and 75 of this code may attempt to convert a null pointer to a uint8_t* type and attempt to perform an addition operation on top of that pointer. This behavior is undefined, and the undefined result depends on the specific compiler and runtime environment. In some cases, this may cause the program to crash.
The code on lines 41, 58, and 75 of this code may attempt to convert a null pointer to a uint8_t* type and attempt to perform an addition operation on top of that pointer. This behavior is undefined, and the undefined result depends on the specific compiler and runtime environment. In some cases, this may cause the program to crash.
jming912 commented 2023-05-26 22:53:00 -05:00 (Migrated from github.com)

for example:
if (!rc || ((uint8_t )rc) + size > (uint8_t)PICO_DEBUG_MALLOC_LOW_WATER) {
printf("malloc %d %p->%p\n", (uint) size, rc, ((uint8_t *) rc) + size);

for example: if (!rc || ((uint8_t *)rc) + size > (uint8_t*)PICO_DEBUG_MALLOC_LOW_WATER) { printf("malloc %d %p->%p\n", (uint) size, rc, ((uint8_t *) rc) + size);
kilograham commented 2023-05-27 10:00:53 -05:00 (Migrated from github.com)

Is this fixing an actual compiler warning? This is also in a debug path only.

Is this fixing an actual compiler warning? This is also in a debug path only.
peterharperuk commented 2024-08-09 08:02:14 -05:00 (Migrated from github.com)

Fixed I think

Fixed I think
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#1397
No description provided.