raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.68k stars 917 forks source link

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

Closed jming912 closed 2 months ago

jming912 commented 1 year ago
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 1 year ago

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 1 year ago

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

peterharperuk commented 2 months ago

Fixed I think