Skip to content

Commit f9c7828

Browse files
committed
fix parameter order in calloc() calls
calloc(nmemb, bytes) allocates memory for an array of _nmemb_ elements of size _bytes_
1 parent e1651f1 commit f9c7828

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

usermods/audioreactive/audio_reactive.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,11 @@ static bool alocateFFTBuffers(void) {
455455

456456
if (vReal) free(vReal); // should not happen
457457
if (vImag) free(vImag); // should not happen
458-
if ((vReal = (float*) calloc(sizeof(float), samplesFFT)) == nullptr) return false; // calloc or die
459-
if ((vImag = (float*) calloc(sizeof(float), samplesFFT)) == nullptr) return false;
458+
if ((vReal = (float*) calloc(samplesFFT, sizeof(float))) == nullptr) return false; // calloc or die
459+
if ((vImag = (float*) calloc(samplesFFT, sizeof(float))) == nullptr) return false;
460460
#ifdef FFT_MAJORPEAK_HUMAN_EAR
461461
if (pinkFactors) free(pinkFactors);
462-
if ((pinkFactors = (float*) calloc(sizeof(float), samplesFFT)) == nullptr) return false;
462+
if ((pinkFactors = (float*) calloc(samplesFFT, sizeof(float))) == nullptr) return false;
463463
#endif
464464

465465
#ifdef SR_DEBUG
@@ -510,7 +510,7 @@ void FFTcode(void * parameter)
510510
static float* oldSamples = nullptr; // previous 50% of samples
511511
static bool haveOldSamples = false; // for sliding window FFT
512512
bool usingOldSamples = false;
513-
if (!oldSamples) oldSamples = (float*) calloc(sizeof(float), samplesFFT_2); // allocate on first run
513+
if (!oldSamples) oldSamples = (float*) calloc(samplesFFT_2, sizeof(float)); // allocate on first run
514514
if (!oldSamples) { disableSoundProcessing = true; return; } // no memory -> die
515515
#endif
516516

@@ -526,7 +526,7 @@ void FFTcode(void * parameter)
526526
// recommended version optimized by @softhack007 (API version 1.9)
527527
#if defined(WLED_ENABLE_HUB75MATRIX) && defined(CONFIG_IDF_TARGET_ESP32)
528528
static float* windowWeighingFactors = nullptr;
529-
if (!windowWeighingFactors) windowWeighingFactors = (float*) calloc(sizeof(float), samplesFFT); // cache for FFT windowing factors - use heap
529+
if (!windowWeighingFactors) windowWeighingFactors = (float*) calloc(samplesFFT, sizeof(float)); // cache for FFT windowing factors - use heap
530530
#else
531531
static float windowWeighingFactors[samplesFFT] = {0.0f}; // cache for FFT windowing factors - use global RAM
532532
#endif

wled00/FX_fcn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void Segment::allocLeds() {
125125
portEXIT_CRITICAL(&ledsrgb_mux);
126126

127127
if (oldLedsRgb) free(oldLedsRgb); // we need a bigger buffer, so free the old one first
128-
CRGB* newLedsRgb = (CRGB*)calloc(1, size); // WLEDMM This is an OS call, so we should not wrap it in portEnterCRITICAL
128+
CRGB* newLedsRgb = (CRGB*)calloc(size, 1); // WLEDMM This is an OS call, so we should not wrap it in portEnterCRITICAL
129129

130130
portENTER_CRITICAL(&ledsrgb_mux);
131131
ledsrgb = newLedsRgb;

0 commit comments

Comments
 (0)