aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2017-02-28 01:02:25 +0100
committerEven Rouault <even.rouault@spatialys.com>2017-02-28 17:02:53 +0100
commit21d16428760469717fd25ebf9d03c286db935c66 (patch)
tree0747dd9d46c106e11a4e85d0caaacc002f2557e9
parent8bf1acf2692e7628c2a7b41ad53d876f9b9b09e9 (diff)
downloadPROJ-21d16428760469717fd25ebf9d03c286db935c66.tar.gz
PROJ-21d16428760469717fd25ebf9d03c286db935c66.zip
Enable cppcheck and fix related mostly false-positive warnings
-rw-r--r--src/PJ_healpix.c16
-rw-r--r--src/PJ_labrd.c6
-rw-r--r--src/PJ_lsat.c15
-rw-r--r--src/PJ_misrsom.c13
-rw-r--r--src/PJ_mod_ster.c3
-rw-r--r--src/PJ_oea.c2
-rw-r--r--src/emess.c15
-rw-r--r--src/geodesic.c5
-rw-r--r--src/geodtest.c12
-rw-r--r--src/pj_datum_set.c5
-rw-r--r--src/pj_gc_reader.c15
-rw-r--r--src/pj_init.c3
-rw-r--r--src/pj_phi2.c10
-rw-r--r--src/proj_etmerc.c10
-rwxr-xr-xtravis/linux_gcc/before_install.sh10
15 files changed, 106 insertions, 34 deletions
diff --git a/src/PJ_healpix.c b/src/PJ_healpix.c
index edd0d978..7e1245a6 100644
--- a/src/PJ_healpix.c
+++ b/src/PJ_healpix.c
@@ -446,7 +446,6 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
int inverse) {
XY xy;
double v[2];
- double a[2];
double c[2];
double vector[2];
double v_min_c[2];
@@ -467,8 +466,7 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
if (inverse == 0) {
/* Rotate (x, y) about its polar cap tip and then translate it to
north_square or south_square. */
- a[0] = -3*M_FORTPI + pole*M_HALFPI;
- a[1] = M_HALFPI;
+
if (capmap.region == north) {
pole = north_square;
tmpRot = rot[get_rotate_index(capmap.cn - pole)];
@@ -479,8 +477,7 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
} else {
/* Inverse function.
Unrotate (x, y) and then translate it back. */
- a[0] = -3*M_FORTPI + capmap.cn*M_HALFPI;
- a[1] = M_HALFPI;
+
/* disassemble */
if (capmap.region == north) {
pole = north_square;
@@ -493,7 +490,14 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
vector_sub(v, c, v_min_c);
dot_product(tmpRot, v_min_c, ret_dot);
- vector_add(ret_dot, a, vector);
+ {
+ double a[2];
+ /* Workaround cppcheck git issue */
+ double* pa = a;
+ pa[0] = -3*M_FORTPI + ((inverse == 0) ? 0 : capmap.cn) *M_HALFPI;
+ pa[1] = M_HALFPI;
+ vector_add(ret_dot, a, vector);
+ }
xy.x = vector[0];
xy.y = vector[1];
diff --git a/src/PJ_labrd.c b/src/PJ_labrd.c
index d0fad627..dfc54478 100644
--- a/src/PJ_labrd.c
+++ b/src/PJ_labrd.c
@@ -46,7 +46,10 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
struct pj_opaque *Q = P->opaque;
- double x2, y2, V1, V2, V3, V4, t, t2, ps, pe, tpe, s;
+ /* t = 0.0 optimization is to avoid a false positive cppcheck warning */
+ /* (cppcheck git beaf29c15867984aa3c2a15cf15bd7576ccde2b3). Might no */
+ /* longer be necessary with later versions. */
+ double x2, y2, V1, V2, V3, V4, t = 0.0, t2, ps, pe, tpe, s;
double I7, I8, I9, I10, I11, d, Re;
int i;
@@ -60,6 +63,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
xy.y += Q->Cb * V1 - Q->Ca * V2 - Q->Cd * V3 + Q->Cc * V4;
ps = Q->p0s + xy.y / Q->kRg;
pe = ps + P->phi0 - Q->p0s;
+
for ( i = 20; i; --i) {
V1 = Q->A * log(tan(M_FORTPI + .5 * pe));
tpe = P->e * sin(pe);
diff --git a/src/PJ_lsat.c b/src/PJ_lsat.c
index 665c0662..a141d568 100644
--- a/src/PJ_lsat.c
+++ b/src/PJ_lsat.c
@@ -42,23 +42,30 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
struct pj_opaque *Q = P->opaque;
int l, nn;
double lamt = 0.0, xlam, sdsq, c, d, s, lamdp = 0.0, phidp, lampp, tanph;
- double lamtp, cl, sd, sp, fac, sav, tanphi;
+ double lamtp, cl, sd, sp, sav, tanphi;
if (lp.phi > M_HALFPI)
lp.phi = M_HALFPI;
else if (lp.phi < -M_HALFPI)
lp.phi = -M_HALFPI;
- lampp = lp.phi >= 0. ? M_HALFPI : M_PI_HALFPI;
+ if (lp.phi >= 0. )
+ lampp = M_HALFPI;
+ else
+ lampp = M_PI_HALFPI;
tanphi = tan(lp.phi);
for (nn = 0;;) {
+ double fac;
sav = lampp;
lamtp = lp.lam + Q->p22 * lampp;
cl = cos(lamtp);
if (fabs(cl) < TOL)
lamtp -= TOL;
- fac = lampp - sin(lampp) * (cl < 0. ? -M_HALFPI : M_HALFPI);
- for (l = 50; l; --l) {
+ if( cl < 0 )
+ fac = lampp + sin(lampp) * M_HALFPI;
+ else
+ fac = lampp - sin(lampp) * M_HALFPI;
+ for (l = 50; l >= 0; --l) {
lamt = lp.lam + Q->p22 * sav;
c = cos(lamt);
if (fabs(c) < TOL)
diff --git a/src/PJ_misrsom.c b/src/PJ_misrsom.c
index 358c036a..6f1c9b29 100644
--- a/src/PJ_misrsom.c
+++ b/src/PJ_misrsom.c
@@ -60,21 +60,28 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
struct pj_opaque *Q = P->opaque;
int l, nn;
double lamt = 0.0, xlam, sdsq, c, d, s, lamdp = 0.0, phidp, lampp, tanph;
- double lamtp, cl, sd, sp, fac, sav, tanphi;
+ double lamtp, cl, sd, sp, sav, tanphi;
if (lp.phi > M_HALFPI)
lp.phi = M_HALFPI;
else if (lp.phi < -M_HALFPI)
lp.phi = -M_HALFPI;
- lampp = lp.phi >= 0. ? M_HALFPI : M_PI_HALFPI;
+ if (lp.phi >= 0. )
+ lampp = M_HALFPI;
+ else
+ lampp = M_PI_HALFPI;
tanphi = tan(lp.phi);
for (nn = 0;;) {
+ double fac;
sav = lampp;
lamtp = lp.lam + Q->p22 * lampp;
cl = cos(lamtp);
if (fabs(cl) < TOL)
lamtp -= TOL;
- fac = lampp - sin(lampp) * (cl < 0. ? -M_HALFPI : M_HALFPI);
+ if( cl < 0 )
+ fac = lampp + sin(lampp) * M_HALFPI;
+ else
+ fac = lampp - sin(lampp) * M_HALFPI;
for (l = 50; l; --l) {
lamt = lp.lam + Q->p22 * sav;
if (fabs(c = cos(lamt)) < TOL)
diff --git a/src/PJ_mod_ster.c b/src/PJ_mod_ster.c
index bcf2bf9c..f8c90bc4 100644
--- a/src/PJ_mod_ster.c
+++ b/src/PJ_mod_ster.c
@@ -46,7 +46,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
struct pj_opaque *Q = P->opaque;
int nn;
COMPLEX p, fxy, fpxy, dp;
- double den, rh = 0.0, z, sinz = 0.0, cosz = 0.0, chi, phi = 0.0, dphi, esphi;
+ double den, rh = 0.0, z, sinz = 0.0, cosz = 0.0, chi, phi = 0.0, esphi;
p.r = xy.x;
p.i = xy.y;
@@ -79,6 +79,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
chi = aasin(P->ctx, cosz * Q->schio + p.i * sinz * Q->cchio / rh);
phi = chi;
for (nn = 20; nn ;--nn) {
+ double dphi;
esphi = P->e * sin(phi);
dphi = 2. * atan(tan((M_HALFPI + chi) * .5) *
pow((1. + esphi) / (1. - esphi), P->e * .5)) - M_HALFPI - phi;
diff --git a/src/PJ_oea.c b/src/PJ_oea.c
index 1ad8ddb2..11efb194 100644
--- a/src/PJ_oea.c
+++ b/src/PJ_oea.c
@@ -75,7 +75,9 @@ PJ *PROJECTION(oea) {
if (((Q->n = pj_param(P->ctx, P->params, "dn").f) <= 0.) ||
((Q->m = pj_param(P->ctx, P->params, "dm").f) <= 0.))
+ {
E_ERROR(-39)
+ }
else {
Q->theta = pj_param(P->ctx, P->params, "rtheta").f;
Q->sp0 = sin(P->phi0);
diff --git a/src/emess.c b/src/emess.c
index 0c7f6c9e..7b6ebf75 100644
--- a/src/emess.c
+++ b/src/emess.c
@@ -37,13 +37,18 @@ emess(int code, char *fmt, ...) {
putc('\n', stderr);
/* if |code|==2, print errno code data */
if (code == 2 || code == -2)
- (void)fprintf(stderr, "Sys errno: %d: %s\n",
- errno,
+ {
+ int my_errno = errno;
#ifdef HAVE_STRERROR
- strerror(errno));
-#else
- "<system mess. texts unavail.>");
+ const char* my_strerror = strerror(my_errno);
+#endif
+#ifndef HAVE_STRERROR
+ const char* my_strerror = "<system mess. texts unavail.>";
#endif
+ (void)fprintf(stderr, "Sys errno: %d: %s\n",
+ my_errno, my_strerror);
+ }
+
/* post remainder of call data */
(void)vfprintf(stderr,fmt,args);
va_end(args);
diff --git a/src/geodesic.c b/src/geodesic.c
index 5c038a33..d93268c6 100644
--- a/src/geodesic.c
+++ b/src/geodesic.c
@@ -85,7 +85,10 @@ static void Init() {
tolb = tol0 * tol2;
xthresh = 1000 * tol2;
degree = pi/180;
- NaN = sqrt(-1.0);
+ {
+ double minus1 = -1.0;
+ NaN = sqrt(minus1);
+ }
init = 1;
}
}
diff --git a/src/geodtest.c b/src/geodtest.c
index 5fd00cb8..7b36f64b 100644
--- a/src/geodtest.c
+++ b/src/geodtest.c
@@ -336,9 +336,13 @@ static int GeodSolve12() {
static int GeodSolve14() {
/* Check fix for inverse ignoring lon12 = nan */
- double azi1, azi2, s12, nan = sqrt(-1.0);
+ double azi1, azi2, s12, nan;
struct geod_geodesic g;
int result = 0;
+ {
+ double minus1 = -1.0;
+ nan = sqrt(minus1);
+ }
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, 0, 0, 1, nan, &s12, &azi1, &azi2);
result += azi1 == azi1 ? 1 : 0;
@@ -473,9 +477,13 @@ static int GeodSolve33() {
static int GeodSolve55() {
/* Check fix for nan + point on equator or pole not returning all nans in
* Geodesic::Inverse, found 2015-09-23. */
- double azi1, azi2, s12, nan = sqrt(-1.0);
+ double azi1, azi2, s12, nan;
struct geod_geodesic g;
int result = 0;
+ {
+ double minus1 = -1.0;
+ nan = sqrt(minus1);
+ }
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, nan, 0, 0, 90, &s12, &azi1, &azi2);
result += azi1 == azi1 ? 1 : 0;
diff --git a/src/pj_datum_set.c b/src/pj_datum_set.c
index 194bfe57..3fba68f4 100644
--- a/src/pj_datum_set.c
+++ b/src/pj_datum_set.c
@@ -71,7 +71,10 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
char entry[100];
strcpy( entry, "ellps=" );
- strncat( entry, pj_datums[i].ellipse_id, 80 );
+ strncpy( entry + strlen(entry), pj_datums[i].ellipse_id,
+ sizeof(entry) - 1 - strlen(entry) );
+ entry[ sizeof(entry) - 1 ] = '\0';
+
curr = curr->next = pj_mkparam(entry);
}
diff --git a/src/pj_gc_reader.c b/src/pj_gc_reader.c
index 458737c1..4b54d05a 100644
--- a/src/pj_gc_reader.c
+++ b/src/pj_gc_reader.c
@@ -70,12 +70,21 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
if( catalog->entry_count == entry_max )
{
+ PJ_GridCatalogEntry* new_entries;
entry_max = entry_max * 2;
- catalog->entries = (PJ_GridCatalogEntry *)
+ new_entries = (PJ_GridCatalogEntry *)
realloc(catalog->entries,
entry_max * sizeof(PJ_GridCatalogEntry));
- if (catalog->entries == NULL )
+ if (new_entries == NULL )
+ {
+ int i;
+ for( i = 0; i < catalog->entry_count; i++ )
+ free( catalog->entries[i].definition );
+ free( catalog->catalog_name );
+ free( catalog );
return NULL;
+ }
+ catalog->entries = new_entries;
}
}
@@ -184,8 +193,6 @@ static int pj_gc_readentry(projCtx ctx, PAFile fid, PJ_GridCatalogEntry *entry)
}
else
{
- memset( entry, 0, sizeof(PJ_GridCatalogEntry));
-
entry->definition = strdup( tokens[0] );
entry->region.ll_long = dmstor_ctx( ctx, tokens[1], NULL );
entry->region.ll_lat = dmstor_ctx( ctx, tokens[2], NULL );
diff --git a/src/pj_init.c b/src/pj_init.c
index 62901fdf..1f09b0f2 100644
--- a/src/pj_init.c
+++ b/src/pj_init.c
@@ -288,7 +288,8 @@ get_init(projCtx ctx, paralist **start, paralist *next, char *name,
paralist *init_items = NULL;
const paralist *orig_next = next;
- (void)strncpy(fname, name, MAX_PATH_FILENAME + ID_TAG_MAX + 1);
+ (void)strncpy(fname, name, sizeof(fname)-2);
+ fname[sizeof(fname)-2] = '\0';
/*
** Search for file/key pair in cache
diff --git a/src/pj_phi2.c b/src/pj_phi2.c
index 60b36ec4..fa6d9950 100644
--- a/src/pj_phi2.c
+++ b/src/pj_phi2.c
@@ -6,18 +6,22 @@
double
pj_phi2(projCtx ctx, double ts, double e) {
- double eccnth, Phi, con, dphi;
+ double eccnth, Phi, con;
int i;
eccnth = .5 * e;
Phi = M_HALFPI - 2. * atan (ts);
i = N_ITER;
- do {
+ for(;;) {
+ double dphi;
con = e * sin (Phi);
dphi = M_HALFPI - 2. * atan (ts * pow((1. - con) /
(1. + con), eccnth)) - Phi;
Phi += dphi;
- } while ( fabs(dphi) > TOL && --i);
+ if( fabs(dphi) > TOL && --i )
+ continue;
+ break;
+ }
if (i <= 0)
pj_ctx_set_errno( ctx, -18 );
return Phi;
diff --git a/src/proj_etmerc.c b/src/proj_etmerc.c
index 2c07808b..cbca9bbb 100644
--- a/src/proj_etmerc.c
+++ b/src/proj_etmerc.c
@@ -416,15 +416,21 @@ PJ *PROJECTION(utm) {
P->y0 = pj_param (P->ctx, P->params, "bsouth").i ? 10000000. : 0.;
P->x0 = 500000.;
if (pj_param (P->ctx, P->params, "tzone").i) /* zone input ? */
- if ((zone = pj_param(P->ctx, P->params, "izone").i) > 0 && zone <= 60)
+ {
+ zone = pj_param(P->ctx, P->params, "izone").i;
+ if (zone > 0 && zone <= 60)
--zone;
else
E_ERROR(-35)
+ }
else /* nearest central meridian input */
- if ((zone = (int)(floor ((adjlon (P->lam0) + M_PI) * 30. / M_PI))) < 0)
+ {
+ zone = (int)(floor ((adjlon (P->lam0) + M_PI) * 30. / M_PI));
+ if (zone < 0)
zone = 0;
else if (zone >= 60)
zone = 59;
+ }
P->lam0 = (zone + .5) * M_PI / 30. - M_PI;
P->k0 = 0.9996;
P->phi0 = 0.;
diff --git a/travis/linux_gcc/before_install.sh b/travis/linux_gcc/before_install.sh
index d09c6ef1..31805e80 100755
--- a/travis/linux_gcc/before_install.sh
+++ b/travis/linux_gcc/before_install.sh
@@ -1,5 +1,15 @@
#!/bin/bash
+sudo apt-get install -y cppcheck
+
+cppcheck --inline-suppr --template='{file}:{line},{severity},{id},{message}' --enable=all --inconclusive --std=posix -DPJ_SELFTEST=1 src/*.c 2>/tmp/cppcheck.txt
+
+grep "error," /tmp/cppcheck.txt
+if [[ $? -eq 0 ]] ; then
+ echo "cppcheck failed"
+ exit 1
+fi
+
set -e
./travis/before_install.sh