diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-10-28 09:03:10 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-10-28 09:03:10 +0100 |
| commit | 4330f9fa4391b4d39c52c972c75327ed2ba6ce33 (patch) | |
| tree | d2718cc258d02faee018c96602f84c814cba5fce | |
| parent | e2d5b13f3442a8e88093a9d68e1be550194a4d77 (diff) | |
| download | PROJ-4330f9fa4391b4d39c52c972c75327ed2ba6ce33.tar.gz PROJ-4330f9fa4391b4d39c52c972c75327ed2ba6ce33.zip | |
Various fixes/workarounds to make cppcheck 1.72 (Ubuntu 16.04) and HEAD/1.90dev happy (fixes #1648)
| -rwxr-xr-x | scripts/cppcheck.sh | 15 | ||||
| -rw-r--r-- | src/4D_api.cpp | 8 | ||||
| -rw-r--r-- | src/apply_vgridshift.cpp | 28 | ||||
| -rw-r--r-- | src/apps/gie.cpp | 4 | ||||
| -rw-r--r-- | src/apps/optargpm.h | 4 | ||||
| -rw-r--r-- | src/apps/proj.cpp | 3 | ||||
| -rw-r--r-- | src/conversions/axisswap.cpp | 14 | ||||
| -rw-r--r-- | src/iso19111/factory.cpp | 24 | ||||
| -rw-r--r-- | src/open_lib.cpp | 1 | ||||
| -rw-r--r-- | src/proj_mdist.cpp | 5 | ||||
| -rw-r--r-- | src/projections/healpix.cpp | 58 | ||||
| -rw-r--r-- | src/projections/sch.cpp | 20 | ||||
| -rw-r--r-- | src/projections/stere.cpp | 3 | ||||
| -rw-r--r-- | src/transformations/deformation.cpp | 12 |
14 files changed, 94 insertions, 105 deletions
diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index 19620207..f42d5f6d 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -1,5 +1,4 @@ #!/bin/bash -# Note: tested with cppcheck 1.61 as shipped with Ubuntu 14.04 echo `cppcheck --version` LOG_FILE=/tmp/cppcheck_proj.txt @@ -23,7 +22,7 @@ for dirname in ${TOPDIR}/src; do echo "Running cppcheck on $dirname... (can be long)" if ! cppcheck --inline-suppr --template='{file}:{line},{severity},{id},{message}' \ --enable=all --inconclusive --std=posix \ - -DCPPCHECK -D__cplusplus=201103L -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H \ + -DCPPCHECK -D__cplusplus=201103L -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H -DNAN \ -I${TOPDIR}/src -I${TOPDIR}/include \ "$dirname" \ -j 8 >>${LOG_FILE} 2>&1 ; then @@ -34,7 +33,17 @@ done ret_code=0 -grep -v "unmatchedSuppression" ${LOG_FILE} | grep -v "nn.hpp" | grep -v "nlohmann/json.hpp" | grep -v "wkt1_generated_parser" | grep -v "wkt2_generated_parser" > ${LOG_FILE}.tmp +grep -v "unmatchedSuppression" ${LOG_FILE} \ + | grep -v "nn.hpp" \ + | grep -v "nlohmann/json.hpp" \ + | grep -v "wkt1_generated_parser" \ + | grep -v "wkt2_generated_parser" \ + | grep -v "passedByValue,Function parameter 'coo' should be passed by const reference" \ + | grep -v "passedByValue,Function parameter 'lpz' should be passed by const reference" \ + | grep -v "passedByValue,Function parameter 'xyz' should be passed by const reference" \ + | grep -v "passedByValue,Function parameter 'in' should be passed by const reference" \ + | grep -v "knownConditionTrueFalse,Condition '!allowEmptyIntersection' is always false" \ + > ${LOG_FILE}.tmp mv ${LOG_FILE}.tmp ${LOG_FILE} if grep "null pointer" ${LOG_FILE} ; then diff --git a/src/4D_api.cpp b/src/4D_api.cpp index c182b3bf..71c708de 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -879,7 +879,9 @@ static void reproject_bbox(PJ* pjGeogToCrs, maxx = -maxx; maxy = -maxy; - double x[21 * 4], y[21 * 4]; + std::vector<double> x, y; + x.resize(21 * 4); + y.resize(21 * 4); for( int j = 0; j <= 20; j++ ) { x[j] = west_lon + j * (east_lon - west_lon) / 20; @@ -893,8 +895,8 @@ static void reproject_bbox(PJ* pjGeogToCrs, } proj_trans_generic ( pjGeogToCrs, PJ_FWD, - x, sizeof(double), 21 * 4, - y, sizeof(double), 21 * 4, + &x[0], sizeof(double), 21 * 4, + &y[0], sizeof(double), 21 * 4, nullptr, 0, 0, nullptr, 0, 0); for( int j = 0; j < 21 * 4; j++ ) diff --git a/src/apply_vgridshift.cpp b/src/apply_vgridshift.cpp index 0c1db3dd..daa44858 100644 --- a/src/apply_vgridshift.cpp +++ b/src/apply_vgridshift.cpp @@ -119,13 +119,13 @@ static double read_vgrid_value( PJ *defn, PJ_LP input, double vmultiplier, int * /* load the grid shift info if we don't have it. */ if( ct->cvs == nullptr ) { - if( !pj_gridinfo_load( pj_get_ctx(defn), gi ) || ct->cvs == nullptr ) - { - pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID ); - return PJD_ERR_FAILED_TO_LOAD_GRID; - } + pj_gridinfo_load( pj_get_ctx(defn), gi ); + } + if( ct->cvs == nullptr ) + { + pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID ); + return PJD_ERR_FAILED_TO_LOAD_GRID; } - /* Interpolation a location within the grid */ grid_x = (input.lam - ct->ll.lam) / ct->del.lam; @@ -271,7 +271,7 @@ int pj_apply_vgridshift( PJ *defn, const char *listname, if( value == HUGE_VAL ) { int itable; - char gridlist[3000]; + std::string gridlist; proj_log_debug(defn, "pj_apply_vgridshift(): failed to find a grid shift table for\n" @@ -279,23 +279,17 @@ int pj_apply_vgridshift( PJ *defn, const char *listname, x[io] * RAD_TO_DEG, y[io] * RAD_TO_DEG ); - gridlist[0] = '\0'; for( itable = 0; itable < *gridlist_count_p; itable++ ) { PJ_GRIDINFO *gi = tables[itable]; - if( strlen(gridlist) + strlen(gi->gridname) > sizeof(gridlist)-100 ) - { - strcat( gridlist, "..." ); - break; - } - if( itable == 0 ) - sprintf( gridlist, " tried: %s", gi->gridname ); + gridlist += " tried: "; else - sprintf( gridlist+strlen(gridlist), ",%s", gi->gridname ); + gridlist += ','; + gridlist += gi->gridname; } - proj_log_debug(defn, "%s", gridlist); + proj_log_debug(defn, "%s", gridlist.c_str()); pj_ctx_set_errno( defn->ctx, PJD_ERR_GRID_AREA ); return PJD_ERR_GRID_AREA; diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 4ae97130..6a67b55d 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -874,7 +874,7 @@ static int expect_failure_with_errno_message (int expected, int got) { /* For test purposes, we want to call a transformation of the same */ /* dimensionality as the number of dimensions given in accept */ -static PJ_COORD expect_trans_n_dim (PJ_COORD ci) { +static PJ_COORD expect_trans_n_dim (const PJ_COORD& ci) { if (4==T.dimensions_given_at_last_accept) return proj_trans (T.P, T.dir, ci); @@ -1192,7 +1192,7 @@ static int errno_from_err_const (const char *err_const) { const size_t n = sizeof lookup / sizeof lookup[0]; size_t i, len; int ret; - char tolower_err_const[100]; + char tolower_err_const[100] = {}; /* Make a lower case copy for matching */ for (i = 0; i < 99; i++) { diff --git a/src/apps/optargpm.h b/src/apps/optargpm.h index f293ad98..4e8dd9c7 100644 --- a/src/apps/optargpm.h +++ b/src/apps/optargpm.h @@ -286,9 +286,7 @@ int opt_input_loop (OPTARGS *opt, int binary) { return 1; /* ignore non-existing files - go on! */ - if (nullptr==opt->input) - return opt_input_loop (opt, binary); - return 0; + return opt_input_loop (opt, binary); } diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 888d723f..7fe08023 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -290,7 +290,8 @@ static void vprocess(FILE *fid) { } int main(int argc, char **argv) { - char *arg, *pargv[MAX_PARGS]; + char *arg; + char *pargv[MAX_PARGS] = {}; char **eargv = argv; FILE *fid; int pargc = 0, eargc = 0, mon = 0; diff --git a/src/conversions/axisswap.cpp b/src/conversions/axisswap.cpp index 15ec016b..4ae2b4e4 100644 --- a/src/conversions/axisswap.cpp +++ b/src/conversions/axisswap.cpp @@ -78,7 +78,8 @@ static PJ_XY forward_2d(PJ_LP lp, PJ *P) { unsigned int i; PJ_COORD out, in; - in.lp = lp; + in.v[0] = lp.lam; + in.v[1] = lp.phi; out = proj_coord_error(); for (i=0; i<2; i++) @@ -93,7 +94,8 @@ static PJ_LP reverse_2d(PJ_XY xy, PJ *P) { unsigned int i; PJ_COORD out, in; - in.xy = xy; + in.v[0] = xy.x; + in.v[1] = xy.y; out = proj_coord_error(); for (i=0; i<2; i++) @@ -108,7 +110,9 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { unsigned int i; PJ_COORD out, in; - in.lpz = lpz; + in.v[0] = lpz.lam; + in.v[1] = lpz.phi; + in.v[2] = lpz.z; out = proj_coord_error(); for (i=0; i<3; i++) @@ -123,7 +127,9 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { PJ_COORD in, out; out = proj_coord_error(); - in.xyz = xyz; + in.v[0] = xyz.x; + in.v[1] = xyz.y; + in.v[2] = xyz.z; for (i=0; i<3; i++) out.v[Q->axis[i]] = in.v[i] * Q->sign[i]; diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 6fef6366..e0a1b084 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -4379,19 +4379,17 @@ AuthorityFactory::createObjectsFromName( const auto &listOfRow = pair.second; for (const auto &row : listOfRow) { const auto &name = row[3]; - if (approximateMatch) { - bool match = - ci_find(name, searchedNameWithoutDeprecated) != - std::string::npos; - if (!match) { - const auto &canonicalizedName(pair.first); - match = ci_find(canonicalizedName, - canonicalizedSearchedName) != - std::string::npos; - } - if (!match) { - continue; - } + bool match = + ci_find(name, searchedNameWithoutDeprecated) != + std::string::npos; + if (!match) { + const auto &canonicalizedName(pair.first); + match = ci_find(canonicalizedName, + canonicalizedSearchedName) != + std::string::npos; + } + if (!match) { + continue; } const auto &auth_name = row[1]; diff --git a/src/open_lib.cpp b/src/open_lib.cpp index 05e01db2..7fedb28b 100644 --- a/src/open_lib.cpp +++ b/src/open_lib.cpp @@ -245,6 +245,7 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode, { if( out_full_filename != nullptr && out_full_filename_size > 0 ) { + // cppcheck-suppress nullPointer strncpy(out_full_filename, sysname, out_full_filename_size); out_full_filename[out_full_filename_size-1] = '\0'; } diff --git a/src/proj_mdist.cpp b/src/proj_mdist.cpp index d15a692c..c515f6c5 100644 --- a/src/proj_mdist.cpp +++ b/src/proj_mdist.cpp @@ -49,8 +49,8 @@ struct MDIST { void * proj_mdist_ini(double es) { double numf, numfi, twon1, denf, denfi, ens, T, twon; - double den, El, Es; - double E[MAX_ITER]; + double den, El = 1., Es = 1.; + double E[MAX_ITER] = { 1. }; struct MDIST *b; int i, j; @@ -59,7 +59,6 @@ proj_mdist_ini(double es) { numf = twon1 = denfi = 1.; denf = 1.; twon = 4.; - Es = El = E[0] = 1.; for (i = 1; i < MAX_ITER ; ++i) { numf *= (twon1 * twon1); den = twon * denf * denf * twon1; diff --git a/src/projections/healpix.cpp b/src/projections/healpix.cpp index 4acb4f69..b065a310 100644 --- a/src/projections/healpix.cpp +++ b/src/projections/healpix.cpp @@ -192,39 +192,24 @@ static int in_image(double x, double y, int proj, int north_square, sizeof(healpixVertsJit[0]), healpixVertsJit, x, y); } else { /** - * Assigning each element by index to avoid warnings such as - * 'initializer element is not computable at load time'. - * Before C99 this was not allowed and to keep as portable as - * possible we do it the C89 way here. * We need to assign the array this way because the input is * dynamic (north_square and south_square vars are unknown at * compile time). **/ - double rhealpixVertsJit[12][2]; - rhealpixVertsJit[0][0] = -M_PI - EPS; - rhealpixVertsJit[0][1] = M_FORTPI + EPS; - rhealpixVertsJit[1][0] = -M_PI + north_square*M_HALFPI- EPS; - rhealpixVertsJit[1][1] = M_FORTPI + EPS; - rhealpixVertsJit[2][0] = -M_PI + north_square*M_HALFPI- EPS; - rhealpixVertsJit[2][1] = 3*M_FORTPI + EPS; - rhealpixVertsJit[3][0] = -M_PI + (north_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[3][1] = 3*M_FORTPI + EPS; - rhealpixVertsJit[4][0] = -M_PI + (north_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[4][1] = M_FORTPI + EPS; - rhealpixVertsJit[5][0] = M_PI + EPS; - rhealpixVertsJit[5][1] = M_FORTPI + EPS; - rhealpixVertsJit[6][0] = M_PI + EPS; - rhealpixVertsJit[6][1] = -M_FORTPI - EPS; - rhealpixVertsJit[7][0] = -M_PI + (south_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[7][1] = -M_FORTPI - EPS; - rhealpixVertsJit[8][0] = -M_PI + (south_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[8][1] = -3*M_FORTPI - EPS; - rhealpixVertsJit[9][0] = -M_PI + south_square*M_HALFPI - EPS; - rhealpixVertsJit[9][1] = -3*M_FORTPI - EPS; - rhealpixVertsJit[10][0] = -M_PI + south_square*M_HALFPI - EPS; - rhealpixVertsJit[10][1] = -M_FORTPI - EPS; - rhealpixVertsJit[11][0] = -M_PI - EPS; - rhealpixVertsJit[11][1] = -M_FORTPI - EPS; + double rhealpixVertsJit[][2] = { + { -M_PI - EPS, M_FORTPI + EPS }, + { -M_PI + north_square*M_HALFPI- EPS, M_FORTPI + EPS }, + { -M_PI + north_square*M_HALFPI- EPS, 3*M_FORTPI + EPS }, + { -M_PI + (north_square + 1.0)*M_HALFPI + EPS, 3*M_FORTPI + EPS }, + { -M_PI + (north_square + 1.0)*M_HALFPI + EPS, M_FORTPI + EPS}, + { M_PI + EPS, M_FORTPI + EPS }, + { M_PI + EPS, -M_FORTPI - EPS }, + { -M_PI + (south_square + 1.0)*M_HALFPI + EPS, -M_FORTPI - EPS }, + { -M_PI + (south_square + 1.0)*M_HALFPI + EPS, -3*M_FORTPI - EPS }, + { -M_PI + south_square*M_HALFPI - EPS, -3*M_FORTPI - EPS }, + { -M_PI + south_square*M_HALFPI - EPS, -M_FORTPI - EPS }, + { -M_PI - EPS, -M_FORTPI - EPS } + }; return pnpoly((int)sizeof(rhealpixVertsJit)/ sizeof(rhealpixVertsJit[0]), rhealpixVertsJit, x, y); @@ -459,8 +444,6 @@ static CapMap get_cap(double x, double y, int north_square, int south_square, static PJ_XY combine_caps(double x, double y, int north_square, int south_square, int inverse) { PJ_XY xy; - double v[2]; - double c[2]; double vector[2]; double v_min_c[2]; double ret_dot[2]; @@ -474,8 +457,8 @@ static PJ_XY combine_caps(double x, double y, int north_square, int south_square return xy; } - v[0] = x; v[1] = y; - c[0] = capmap.x; c[1] = capmap.y; + double v[] = {x, y}; + double c[] = {capmap.x, capmap.y}; if (inverse == 0) { /* Rotate (x, y) about its polar cap tip and then translate it to @@ -505,11 +488,10 @@ static PJ_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); { - double a[2]; - /* Workaround cppcheck git issue */ - double* pa = a; - pa[0] = -3*M_FORTPI + ((inverse == 0) ? pole : capmap.cn) *M_HALFPI; - pa[1] = ((capmap.region == CapMap::north) ? 1 : -1) *M_HALFPI; + double a[] = { + -3*M_FORTPI + ((inverse == 0) ? pole : capmap.cn) *M_HALFPI, + ((capmap.region == CapMap::north) ? 1 : -1) *M_HALFPI + }; vector_add(ret_dot, a, vector); } diff --git a/src/projections/sch.cpp b/src/projections/sch.cpp index e302c1da..261555a7 100644 --- a/src/projections/sch.cpp +++ b/src/projections/sch.cpp @@ -59,12 +59,12 @@ static PJ_LPZ sch_inverse3d(PJ_XYZ xyz, PJ *P) { PJ_LPZ lpz = {0.0, 0.0, 0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double temp[3]; - double pxyz[3]; - /* Local lat,lon using radius */ - pxyz[0] = xyz.y * P->a / Q->rcurv; - pxyz[1] = xyz.x * P->a / Q->rcurv; - pxyz[2] = xyz.z; + double pxyz[] = { + xyz.y * P->a / Q->rcurv, + xyz.x * P->a / Q->rcurv, + xyz.z + }; if( pj_Convert_Geodetic_To_Geocentric( &(Q->sph), pxyz[0], pxyz[1], pxyz[2], temp, temp+1, temp+2) != 0) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); @@ -97,8 +97,6 @@ static PJ_XYZ sch_forward3d(PJ_LPZ lpz, PJ *P) { PJ_XYZ xyz = {0.0, 0.0, 0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double temp[3]; - double pxyz[3]; - /* Convert lat lon to geocentric coordinates */ if( pj_Convert_Geodetic_To_Geocentric( &(Q->elp_0), lpz.phi, lpz.lam, lpz.z, temp, temp+1, temp+2 ) != 0 ) { @@ -114,9 +112,11 @@ static PJ_XYZ sch_forward3d(PJ_LPZ lpz, PJ *P) { /* Apply rotation */ - pxyz[0] = Q->transMat[0] * temp[0] + Q->transMat[3] * temp[1] + Q->transMat[6] * temp[2]; - pxyz[1] = Q->transMat[1] * temp[0] + Q->transMat[4] * temp[1] + Q->transMat[7] * temp[2]; - pxyz[2] = Q->transMat[2] * temp[0] + Q->transMat[5] * temp[1] + Q->transMat[8] * temp[2]; + double pxyz[] = { + Q->transMat[0] * temp[0] + Q->transMat[3] * temp[1] + Q->transMat[6] * temp[2], + Q->transMat[1] * temp[0] + Q->transMat[4] * temp[1] + Q->transMat[7] * temp[2], + Q->transMat[2] * temp[0] + Q->transMat[5] * temp[1] + Q->transMat[8] * temp[2] + }; /* Convert to local lat,lon */ pj_Convert_Geocentric_To_Geodetic( &(Q->sph), pxyz[0], pxyz[1], pxyz[2], diff --git a/src/projections/stere.cpp b/src/projections/stere.cpp index afcf5f02..a1bd41e7 100644 --- a/src/projections/stere.cpp +++ b/src/projections/stere.cpp @@ -141,7 +141,6 @@ static PJ_LP stere_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers PJ_LP lp = {0.0,0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, halfpi=0.0; - int i; rho = hypot (xy.x, xy.y); @@ -171,7 +170,7 @@ static PJ_LP stere_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers break; } - for (i = NITER; i--; ) { + for (int i = NITER; i > 0; --i) { sinphi = P->e * sin(phi_l); lp.phi = 2. * atan (tp * pow ((1.+sinphi)/(1.-sinphi), halfe)) - halfpi; if (fabs (phi_l - lp.phi) < CONV) { diff --git a/src/transformations/deformation.cpp b/src/transformations/deformation.cpp index b9e881eb..f1311a54 100644 --- a/src/transformations/deformation.cpp +++ b/src/transformations/deformation.cpp @@ -71,7 +71,7 @@ struct pj_opaque { } // anonymous namespace /********************************************************************************/ -static PJ_XYZ get_grid_shift(PJ* P, PJ_XYZ cartesian) { +static PJ_XYZ get_grid_shift(PJ* P, const PJ_XYZ& cartesian) { /******************************************************************************** Read correction values from grid. The cartesian input coordinates are converted to geodetic coordinates in order look up the correction values @@ -95,7 +95,7 @@ static PJ_XYZ get_grid_shift(PJ* P, PJ_XYZ cartesian) { if (proj_errno(P) == PJD_ERR_GRID_AREA) proj_log_debug(P, "deformation: coordinate (%.3f, %.3f) outside deformation model", - proj_todeg(geodetic.lp.lam), proj_todeg(geodetic.lp.phi)); + proj_todeg(geodetic.lpz.lam), proj_todeg(geodetic.lpz.phi)); /* grid values are stored as mm/yr, we need m/yr */ shift.xyz.x /= 1000; @@ -103,10 +103,10 @@ static PJ_XYZ get_grid_shift(PJ* P, PJ_XYZ cartesian) { shift.xyz.z /= 1000; /* pre-calc cosines and sines */ - sp = sin(geodetic.lp.phi); - cp = cos(geodetic.lp.phi); - sl = sin(geodetic.lp.lam); - cl = cos(geodetic.lp.lam); + sp = sin(geodetic.lpz.phi); + cp = cos(geodetic.lpz.phi); + sl = sin(geodetic.lpz.lam); + cl = cos(geodetic.lpz.lam); /* ENU -> PJ_XYZ */ temp.xyz.x = -sp*cl*shift.enu.n - sl*shift.enu.e + cp*cl*shift.enu.u; |
