Skip to content

Commit 4c93146

Browse files
committed
correct alloc size in d_calloc
1 parent 31e56ae commit 4c93146

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

wled00/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,10 @@ void *d_malloc(size_t size) {
794794
}
795795

796796
void *d_calloc(size_t count, size_t size) {
797-
// similar to d_malloc bus uses heap_caps_calloc
797+
// similar to d_malloc but uses heap_caps_calloc
798798
void *buffer = nullptr;
799799
#if !defined(CONFIG_IDF_TARGET_ESP32)
800-
if (size <= RTC_RAM_THRESHOLD || getContiguousFreeHeap() < 2*MIN_HEAP_SIZE + size)
800+
if ((size * count) <= RTC_RAM_THRESHOLD || getContiguousFreeHeap() < 2*MIN_HEAP_SIZE + (size * count))
801801
buffer = heap_caps_calloc_prefer(count, size, 2, MALLOC_CAP_RTCRAM, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
802802
if (buffer == nullptr) // no RTC RAM allocation: use DRAM
803803
buffer = heap_caps_calloc(count, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); // allocate in any available heap memory
@@ -839,7 +839,7 @@ void *p_malloc(size_t size) {
839839
}
840840

841841
void *p_calloc(size_t count, size_t size) {
842-
// similar to p_malloc bus uses heap_caps_calloc
842+
// similar to p_malloc but uses heap_caps_calloc
843843
if (!psramFound()) return d_calloc(count, size);
844844
void *buffer = heap_caps_calloc_prefer(count, size, 3, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT, MALLOC_CAP_DEFAULT);
845845
return validateFreeHeap(buffer);

0 commit comments

Comments
 (0)