Bug Summary

File:libs/opus-1.1-p2/silk/float/solve_LS_FLP.c
Location:line 129, column 23
Description:The left operand of '-' is a garbage value

Annotated Source Code

1/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifdef HAVE_CONFIG_H1
29#include "config.h"
30#endif
31
32#include "main_FLP.h"
33#include "tuning_parameters.h"
34
35/**********************************************************************
36 * LDL Factorisation. Finds the upper triangular matrix L and the diagonal
37 * Matrix D (only the diagonal elements returned in a vector)such that
38 * the symmetric matric A is given by A = L*D*L'.
39 **********************************************************************/
40static OPUS_INLINEinline void silk_LDL_FLP(
41 silk_floatfloat *A, /* I/O Pointer to Symetric Square Matrix */
42 opus_intint M, /* I Size of Matrix */
43 silk_floatfloat *L, /* I/O Pointer to Square Upper triangular Matrix */
44 silk_floatfloat *Dinv /* I/O Pointer to vector holding the inverse diagonal elements of D */
45);
46
47/**********************************************************************
48 * Function to solve linear equation Ax = b, when A is a MxM lower
49 * triangular matrix, with ones on the diagonal.
50 **********************************************************************/
51static OPUS_INLINEinline void silk_SolveWithLowerTriangularWdiagOnes_FLP(
52 const silk_floatfloat *L, /* I Pointer to Lower Triangular Matrix */
53 opus_intint M, /* I Dim of Matrix equation */
54 const silk_floatfloat *b, /* I b Vector */
55 silk_floatfloat *x /* O x Vector */
56);
57
58/**********************************************************************
59 * Function to solve linear equation (A^T)x = b, when A is a MxM lower
60 * triangular, with ones on the diagonal. (ie then A^T is upper triangular)
61 **********************************************************************/
62static OPUS_INLINEinline void silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP(
63 const silk_floatfloat *L, /* I Pointer to Lower Triangular Matrix */
64 opus_intint M, /* I Dim of Matrix equation */
65 const silk_floatfloat *b, /* I b Vector */
66 silk_floatfloat *x /* O x Vector */
67);
68
69/**********************************************************************
70 * Function to solve linear equation Ax = b, when A is a MxM
71 * symmetric square matrix - using LDL factorisation
72 **********************************************************************/
73void silk_solve_LDL_FLP(
74 silk_floatfloat *A, /* I/O Symmetric square matrix, out: reg. */
75 const opus_intint M, /* I Size of matrix */
76 const silk_floatfloat *b, /* I Pointer to b vector */
77 silk_floatfloat *x /* O Pointer to x solution vector */
78)
79{
80 opus_intint i;
81 silk_floatfloat L[ MAX_MATRIX_SIZE16 ][ MAX_MATRIX_SIZE16 ];
82 silk_floatfloat T[ MAX_MATRIX_SIZE16 ];
83 silk_floatfloat Dinv[ MAX_MATRIX_SIZE16 ]; /* inverse diagonal elements of D*/
84
85 silk_assert( M <= MAX_MATRIX_SIZE );
86
87 /***************************************************
88 Factorize A by LDL such that A = L*D*(L^T),
89 where L is lower triangular with ones on diagonal
90 ****************************************************/
91 silk_LDL_FLP( A, M, &L[ 0 ][ 0 ], Dinv );
92
93 /****************************************************
94 * substitute D*(L^T) = T. ie:
95 L*D*(L^T)*x = b => L*T = b <=> T = inv(L)*b
96 ******************************************************/
97 silk_SolveWithLowerTriangularWdiagOnes_FLP( &L[ 0 ][ 0 ], M, b, T );
1
Calling 'silk_SolveWithLowerTriangularWdiagOnes_FLP'
4
Returning from 'silk_SolveWithLowerTriangularWdiagOnes_FLP'
98
99 /****************************************************
100 D*(L^T)*x = T <=> (L^T)*x = inv(D)*T, because D is
101 diagonal just multiply with 1/d_i
102 ****************************************************/
103 for( i = 0; i < M; i++ ) {
5
Loop condition is false. Execution continues on line 109
104 T[ i ] = T[ i ] * Dinv[ i ];
105 }
106 /****************************************************
107 x = inv(L') * inv(D) * T
108 *****************************************************/
109 silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( &L[ 0 ][ 0 ], M, T, x );
6
Calling 'silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP'
110}
111
112static OPUS_INLINEinline void silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP(
113 const silk_floatfloat *L, /* I Pointer to Lower Triangular Matrix */
114 opus_intint M, /* I Dim of Matrix equation */
115 const silk_floatfloat *b, /* I b Vector */
116 silk_floatfloat *x /* O x Vector */
117)
118{
119 opus_intint i, j;
120 silk_floatfloat temp;
121 const silk_floatfloat *ptr1;
122
123 for( i = M - 1; i >= 0; i-- ) {
7
Assuming 'i' is >= 0
8
Loop condition is true. Entering loop body
10
Loop condition is true. Entering loop body
124 ptr1 = matrix_adr( L, 0, i, M )((L) + ((0)*(M)+(i)));
125 temp = 0;
126 for( j = M - 1; j > i ; j-- ) {
9
Loop condition is false. Execution continues on line 129
11
Loop condition is true. Entering loop body
12
Loop condition is false. Execution continues on line 129
127 temp += ptr1[ j * M ] * x[ j ];
128 }
129 temp = b[ i ] - temp;
13
The left operand of '-' is a garbage value
130 x[ i ] = temp;
131 }
132}
133
134static OPUS_INLINEinline void silk_SolveWithLowerTriangularWdiagOnes_FLP(
135 const silk_floatfloat *L, /* I Pointer to Lower Triangular Matrix */
136 opus_intint M, /* I Dim of Matrix equation */
137 const silk_floatfloat *b, /* I b Vector */
138 silk_floatfloat *x /* O x Vector */
139)
140{
141 opus_intint i, j;
142 silk_floatfloat temp;
143 const silk_floatfloat *ptr1;
144
145 for( i = 0; i < M; i++ ) {
2
Assuming 'i' is >= 'M'
3
Loop condition is false. Execution continues on line 145
146 ptr1 = matrix_adr( L, i, 0, M )((L) + ((i)*(M)+(0)));
147 temp = 0;
148 for( j = 0; j < i; j++ ) {
149 temp += ptr1[ j ] * x[ j ];
150 }
151 temp = b[ i ] - temp;
152 x[ i ] = temp;
153 }
154}
155
156static OPUS_INLINEinline void silk_LDL_FLP(
157 silk_floatfloat *A, /* I/O Pointer to Symetric Square Matrix */
158 opus_intint M, /* I Size of Matrix */
159 silk_floatfloat *L, /* I/O Pointer to Square Upper triangular Matrix */
160 silk_floatfloat *Dinv /* I/O Pointer to vector holding the inverse diagonal elements of D */
161)
162{
163 opus_intint i, j, k, loop_count, err = 1;
164 silk_floatfloat *ptr1, *ptr2;
165 double temp, diag_min_value;
166 silk_floatfloat v[ MAX_MATRIX_SIZE16 ], D[ MAX_MATRIX_SIZE16 ]; /* temp arrays*/
167
168 silk_assert( M <= MAX_MATRIX_SIZE );
169
170 diag_min_value = FIND_LTP_COND_FAC1e-5f * 0.5f * ( A[ 0 ] + A[ M * M - 1 ] );
171 for( loop_count = 0; loop_count < M && err == 1; loop_count++ ) {
172 err = 0;
173 for( j = 0; j < M; j++ ) {
174 ptr1 = matrix_adr( L, j, 0, M )((L) + ((j)*(M)+(0)));
175 temp = matrix_ptr( A, j, j, M )(*((A) + ((j)*(M)+(j)))); /* element in row j column j*/
176 for( i = 0; i < j; i++ ) {
177 v[ i ] = ptr1[ i ] * D[ i ];
178 temp -= ptr1[ i ] * v[ i ];
179 }
180 if( temp < diag_min_value ) {
181 /* Badly conditioned matrix: add white noise and run again */
182 temp = ( loop_count + 1 ) * diag_min_value - temp;
183 for( i = 0; i < M; i++ ) {
184 matrix_ptr( A, i, i, M )(*((A) + ((i)*(M)+(i)))) += ( silk_floatfloat )temp;
185 }
186 err = 1;
187 break;
188 }
189 D[ j ] = ( silk_floatfloat )temp;
190 Dinv[ j ] = ( silk_floatfloat )( 1.0f / temp );
191 matrix_ptr( L, j, j, M )(*((L) + ((j)*(M)+(j)))) = 1.0f;
192
193 ptr1 = matrix_adr( A, j, 0, M )((A) + ((j)*(M)+(0)));
194 ptr2 = matrix_adr( L, j + 1, 0, M)((L) + ((j + 1)*(M)+(0)));
195 for( i = j + 1; i < M; i++ ) {
196 temp = 0.0;
197 for( k = 0; k < j; k++ ) {
198 temp += ptr2[ k ] * v[ k ];
199 }
200 matrix_ptr( L, i, j, M )(*((L) + ((i)*(M)+(j)))) = ( silk_floatfloat )( ( ptr1[ i ] - temp ) * Dinv[ j ] );
201 ptr2 += M; /* go to next column*/
202 }
203 }
204 }
205 silk_assert( err == 0 );
206}
207