libm: Fixed all static analysis warnings.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 08 Aug 2018 12:13:56 -0400
changeset 12084f0092ea3a038
parent 12083 27e29baad4a3
child 12085 61f6f27a9751
libm: Fixed all static analysis warnings.
src/libm/e_rem_pio2.c
src/libm/k_rem_pio2.c
src/libm/math_private.h
     1.1 --- a/src/libm/e_rem_pio2.c	Wed Aug 08 10:26:22 2018 -0400
     1.2 +++ b/src/libm/e_rem_pio2.c	Wed Aug 08 12:13:56 2018 -0400
     1.3 @@ -154,7 +154,7 @@
     1.4  	}
     1.5  	tx[2] = z;
     1.6  	nx = 3;
     1.7 -	while(tx[nx-1]==zero) nx--;	/* skip zero term */
     1.8 +	while((nx > 0) && tx[nx-1]==zero) nx--;	/* skip zero term */
     1.9  	n  =  __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
    1.10  	if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
    1.11  	return n;
     2.1 --- a/src/libm/k_rem_pio2.c	Wed Aug 08 10:26:22 2018 -0400
     2.2 +++ b/src/libm/k_rem_pio2.c	Wed Aug 08 12:13:56 2018 -0400
     2.3 @@ -128,6 +128,8 @@
     2.4  #include "math_libm.h"
     2.5  #include "math_private.h"
     2.6  
     2.7 +#include "SDL_assert.h"
     2.8 +
     2.9  static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
    2.10  
    2.11  static const double PIo2[] = {
    2.12 @@ -147,13 +149,19 @@
    2.13  two24   =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
    2.14  twon24  =  5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
    2.15  
    2.16 -int32_t attribute_hidden __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
    2.17 +int32_t attribute_hidden __kernel_rem_pio2(double *x, double *y, int e0, int nx, const unsigned int prec, const int32_t *ipio2)
    2.18  {
    2.19  	int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
    2.20  	double z,fw,f[20],fq[20],q[20];
    2.21  
    2.22 +	if (nx < 1) {
    2.23 +		return 0;
    2.24 +	}
    2.25 +
    2.26      /* initialize jk*/
    2.27 +	SDL_assert(prec < SDL_arraysize(init_jk));
    2.28  	jk = init_jk[prec];
    2.29 +	SDL_assert(jk > 0);
    2.30  	jp = jk;
    2.31  
    2.32      /* determine jx,jv,q0, note that 3>q0 */
    2.33 @@ -164,6 +172,7 @@
    2.34      /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
    2.35  	j = jv-jx; m = jx+jk;
    2.36  	for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
    2.37 +	for(i=m+1;i<SDL_arraysize(f);i++) f[i] = zero;
    2.38  
    2.39      /* compute q[0],q[1],...q[jk] */
    2.40  	for (i=0;i<=jk;i++) {
    2.41 @@ -179,6 +188,7 @@
    2.42  	    iq[i] =  (int32_t)(z-two24*fw);
    2.43  	    z     =  q[j-1]+fw;
    2.44  	}
    2.45 +	iq[jz] = 0;
    2.46  
    2.47      /* compute n */
    2.48  	z  = scalbn(z,q0);		/* actual value of z */
    2.49 @@ -238,7 +248,8 @@
    2.50      /* chop off zero terms */
    2.51  	if(z==0.0) {
    2.52  	    jz -= 1; q0 -= 24;
    2.53 -	    while(iq[jz]==0) { jz--; q0-=24;}
    2.54 +		SDL_assert(jz >= 0);
    2.55 +	    while(iq[jz]==0) { jz--; SDL_assert(jz >= 0); q0-=24;}
    2.56  	} else { /* break z into 24-bit if necessary */
    2.57  	    z = scalbn(z,-q0);
    2.58  	    if(z>=two24) {
     3.1 --- a/src/libm/math_private.h	Wed Aug 08 10:26:22 2018 -0400
     3.2 +++ b/src/libm/math_private.h	Wed Aug 08 12:13:56 2018 -0400
     3.3 @@ -221,7 +221,7 @@
     3.4       extern double __kernel_sin(double, double, int) attribute_hidden;
     3.5       extern double __kernel_cos(double, double) attribute_hidden;
     3.6       extern double __kernel_tan(double, double, int) attribute_hidden;
     3.7 -     extern int32_t __kernel_rem_pio2(double *, double *, int, int, int,
     3.8 +     extern int32_t __kernel_rem_pio2(double *, double *, int, int, const unsigned int,
     3.9                                    const int32_t *) attribute_hidden;
    3.10  
    3.11  #endif /* _MATH_PRIVATE_H_ */