From: Sinthu Raja M Date: Thu, 17 Jan 2019 11:53:29 +0000 (+0530) Subject: PRSDK-4807 Fix Klocwork issue X-Git-Tag: DEV.AUDIO_PREPROC.01.06.00.00^2~1 X-Git-Url: https://git.ti.com/gitweb?p=processor-sdk%2Faudio-preprocessing.git;a=commitdiff_plain;h=eb5d4f32d74bf310b2f0982a7ffb4e73d0addf38 PRSDK-4807 Fix Klocwork issue Issue: Pointer variables initialized as NULL is used for memcpy and other functions which can possible result in dereferencing NULL pointer. Fix: Added condition to check the Variables are not NULL before it is been used by other functions. --- diff --git a/common/components/mss/src/mssproc.c b/common/components/mss/src/mssproc.c index 87ce6ff..88300c8 100644 --- a/common/components/mss/src/mssproc.c +++ b/common/components/mss/src/mssproc.c @@ -343,7 +343,7 @@ void mss_src_output(mssInst_t *inst, void *out, void *mic_fix[], } /* Check if in the middle of a switch. */ - if(!mss_chkbit(inst->state_bf, MSS_STATE_BIT_SWITCH_SRC)) { + if(!mss_chkbit(inst->state_bf, MSS_STATE_BIT_SWITCH_SRC) && cur_sel_src != NULL) { /* If it is not during a switch, copy the current selected source to output without any modification. */ memcpy(out, cur_sel_src, inst->frame_size*sizeof(linSample)); @@ -369,17 +369,24 @@ void mss_src_output(mssInst_t *inst, void *out, void *mic_fix[], phase_inc = inst->crossfade_phase_inc; output = (linSample *)out; - for(i=0; iframe_size; i++) { -// alpha = (1-utlSin(phase>>16)) / 2; /* to use macros */ - sin_phase = utlSin(phase>>16); /* Q.31 to Q.15 */ - fade_out_alpha = MSS_SIN_PIOVER2/2 - sin_phase/2; /* (1-sin(pha))/2 in Q.14 */ - fade_in_alpha = MSS_SIN_PIOVER2/2 + sin_phase/2; /* (1+sin(pha))/2 in Q.14 */ - fade_out_alpha = mss_MIN(16383, fade_out_alpha); - fade_in_alpha = mss_MIN(16383, fade_in_alpha); - output[i] = frctMul(cur_sel_src[i], 0, fade_out_alpha, 14, 0) + if(cur_sel_src != NULL && new_sel_src != NULL) + { + for(i=0; iframe_size; i++) { +// alpha = (1-utlSin(phase>>16)) / 2; /* to use macros */ + sin_phase = utlSin(phase>>16); /* Q.31 to Q.15 */ + fade_out_alpha = MSS_SIN_PIOVER2/2 - sin_phase/2; /* (1-sin(pha))/2 in Q.14 */ + fade_in_alpha = MSS_SIN_PIOVER2/2 + sin_phase/2; /* (1+sin(pha))/2 in Q.14 */ + fade_out_alpha = mss_MIN(16383, fade_out_alpha); + fade_in_alpha = mss_MIN(16383, fade_in_alpha); + output[i] = frctMul(cur_sel_src[i], 0, fade_out_alpha, 14, 0) +frctMul(new_sel_src[i], 0, fade_in_alpha, 14, 0); - phase += phase_inc; + phase += phase_inc; + } + } + else { + /* error message */ } + inst->crossfade_phase = phase; /* for debugging only */