From fc50efa07fb5de673da7a173fc73c686e5142d08 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Thu, 5 Oct 2017 09:34:10 +0200 Subject: [PATCH] Proper call of calloc() Fixes #868 --- .../c_speech_features/c_speech_features.c | 16 ++++++++-------- native_client/deepspeech_utils.cc | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/native_client/c_speech_features/c_speech_features.c b/native_client/c_speech_features/c_speech_features.c index 1ff6bff9..705ddf1c 100644 --- a/native_client/c_speech_features/c_speech_features.c +++ b/native_client/c_speech_features/c_speech_features.c @@ -102,7 +102,7 @@ csf_fbank(const short* aSignal, unsigned int aSignalLen, int aSampleRate, // Store the total energy in each frame if (aEnergy) { - energy = (csf_float*)calloc(sizeof(csf_float), n_frames); + energy = (csf_float*)calloc(n_frames, sizeof(csf_float)); for (i = 0, idx = 0; i < n_frames; i++) { for (j = 0; j < feat_width; j++, idx++) { energy[i] += pspec[idx]; @@ -116,7 +116,7 @@ csf_fbank(const short* aSignal, unsigned int aSignalLen, int aSampleRate, // Compute the filter-bank energies fbank = csf_get_filterbanks(aNFilters, aNFFT, aSampleRate, aLowFreq, aHighFreq); - feat = (csf_float*)calloc(sizeof(csf_float), n_frames * aNFilters); + feat = (csf_float*)calloc(n_frames * aNFilters, sizeof(csf_float)); for (i = 0, idx = 0, pidx = 0; i < n_frames; i++, idx += aNFilters, pidx += feat_width) { for (j = 0, fidx = 0; j < aNFilters; j++) { @@ -206,7 +206,7 @@ csf_ssc(const short* aSignal, unsigned int aSignalLen, int aSampleRate, // Compute the filter-bank energies fbank = csf_get_filterbanks(aNFilters, aNFFT, aSampleRate, aLowFreq, aHighFreq); - feat = (csf_float*)calloc(sizeof(csf_float), n_frames * aNFilters); + feat = (csf_float*)calloc(n_frames * aNFilters, sizeof(csf_float)); for (i = 0, idx = 0, pidx = 0; i < n_frames; i++, idx += aNFilters, pidx += feat_width) { for (j = 0, fidx = 0; j < aNFilters; j++) { @@ -217,7 +217,7 @@ csf_ssc(const short* aSignal, unsigned int aSignalLen, int aSampleRate, } // Calculate Spectral Sub-band Centroid features - ssc = (csf_float*)calloc(sizeof(csf_float*), n_frames * aNFilters); + ssc = (csf_float*)calloc(n_frames * aNFilters, sizeof(csf_float)); csf_float r = ((aSampleRate / 2) - 1) / (csf_float)(feat_width - 1); for (i = 0, idx = 0, pidx = 0; i < n_frames; i++, idx += aNFilters, pidx += feat_width) { @@ -290,7 +290,7 @@ csf_delta(const csf_float* aFeatures, int aNFrames, int aNFrameLen, int aN) } denominator *= 2; - delta = (csf_float*)calloc(sizeof(csf_float), aNFrames * aNFrameLen); + delta = (csf_float*)calloc(aNFrames * aNFrameLen, sizeof(csf_float)); for (i = 0, idx = 0; i < aNFrames; i++, idx += aNFrameLen) { for (j = 0; j < aNFrameLen; j++) { for (k = -aN; k <= aN; k++) { @@ -315,7 +315,7 @@ csf_get_filterbanks(int aNFilters, int aNFFT, int aSampleRate, aSampleRate / 2 : aHighFreq); int* bin = (int*)malloc(sizeof(int) * (aNFilters + 2)); csf_float* fbank = - (csf_float*)calloc(sizeof(csf_float), aNFilters * feat_width); + (csf_float*)calloc(aNFilters * feat_width, sizeof(csf_float)); for (i = 0; i < aNFilters + 2; i++) { csf_float melpoint = ((highmel - lowmel) / @@ -399,10 +399,10 @@ csf_deframesig(const csf_float* aFrames, int aNFrames, int aSigLen, aSigLen = padlen; } - win_correct = (csf_float*)calloc(sizeof(csf_float), aSigLen); + win_correct = (csf_float*)calloc(aSigLen, sizeof(csf_float)); base = 0; - signal = (csf_float*)calloc(sizeof(csf_float), aSigLen); + signal = (csf_float*)calloc(aSigLen, sizeof(csf_float)); for (i = 0, idx = 0; i < aNFrames; i++) { for (j = 0; j < aFrameLen; j++, idx++) { int sidx = j + base; diff --git a/native_client/deepspeech_utils.cc b/native_client/deepspeech_utils.cc index dbe106c0..aa7c68a6 100644 --- a/native_client/deepspeech_utils.cc +++ b/native_client/deepspeech_utils.cc @@ -30,7 +30,7 @@ audioToInputVector(const short* aBuffer, unsigned int aBufferSize, // Take every other frame (BiRNN stride of 2) and add past/future context int ds_input_length = (n_frames + 1) / 2; // TODO: Use MFCC of silence instead of zero - float* ds_input = (float*)calloc(sizeof(float), ds_input_length * frameSize); + float* ds_input = (float*)calloc(ds_input_length * frameSize, sizeof(float)); for (int i = 0, idx = 0, mfcc_idx = 0; i < ds_input_length; i++, idx += frameSize, mfcc_idx += aNCep * 2) { // Past context