diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-03-12 23:32:03 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-03-14 20:25:12 +0100 |
| commit | a49738902a27624d835e5a6b9983a9803c322996 (patch) | |
| tree | 8f0a7e5302e12ee0b3044a7b87ca2de6bbdfbc27 /src | |
| parent | cde489ce64556e0ad5fa5da64bcb8fd88aee4c39 (diff) | |
| download | PROJ-a49738902a27624d835e5a6b9983a9803c322996.tar.gz PROJ-a49738902a27624d835e5a6b9983a9803c322996.zip | |
Fix (mostly false positive) clang static analyzer warnings about potential null pointer dereference
Diffstat (limited to 'src')
| -rw-r--r-- | src/PJ_pipeline.c | 9 | ||||
| -rw-r--r-- | src/geod_set.c | 2 | ||||
| -rw-r--r-- | src/geodesic.c | 12 | ||||
| -rw-r--r-- | src/pj_datum_set.c | 5 | ||||
| -rw-r--r-- | src/pj_gridcatalog.c | 2 | ||||
| -rw-r--r-- | src/pj_init.c | 3 | ||||
| -rw-r--r-- | src/pj_param.c | 9 |
7 files changed, 28 insertions, 14 deletions
diff --git a/src/PJ_pipeline.c b/src/PJ_pipeline.c index 3f61ad88..2791a4e8 100644 --- a/src/PJ_pipeline.c +++ b/src/PJ_pipeline.c @@ -286,7 +286,9 @@ static void set_ellipsoid(PJ *P) { /* Break the linked list after the global args */ attachment = 0; for (cur = P->params; cur != 0; cur = cur->next) - if (strcmp("step", cur->next->param) == 0) { + /* cur->next will always be non 0 given argv_sentinel presence, */ + /* but this is far from being obvious for a static analyzer */ + if (cur->next != 0 && strcmp(argv_sentinel, cur->next->param) == 0) { attachment = cur->next; cur->next = 0; break; @@ -310,7 +312,10 @@ static void set_ellipsoid(PJ *P) { geod_init(P->geod, P->a, (1 - sqrt (1 - P->es))); /* Re-attach the dangling list */ - cur->next = attachment; + /* Note: cur will always be non 0 given argv_sentinel presence, */ + /* but this is far from being obvious for a static analyzer */ + if( cur != 0 ) + cur->next = attachment; proj_errno_restore (P, err); } diff --git a/src/geod_set.c b/src/geod_set.c index 26a86b61..571a7d20 100644 --- a/src/geod_set.c +++ b/src/geod_set.c @@ -19,7 +19,7 @@ geod_set(int argc, char **argv) { start = curr = pj_mkparam(argv[0]); if (!curr) emess(1, "memory allocation failed"); - for (i = 1; i < argc; ++i) { + for (i = 1; curr != 0 && i < argc; ++i) { curr->next = pj_mkparam(argv[i]); if (!curr->next) emess(1, "memory allocation failed"); diff --git a/src/geodesic.c b/src/geodesic.c index 5121ea98..40dffbc1 100644 --- a/src/geodesic.c +++ b/src/geodesic.c @@ -658,21 +658,21 @@ real geod_genposition(const struct geod_geodesicline* l, S12 = l->c2 * atan2(salp12, calp12) + l->A4 * (B42 - l->B41); } - if (outmask & GEOD_LATITUDE) + if ((outmask & GEOD_LATITUDE) && plat2) *plat2 = lat2; - if (outmask & GEOD_LONGITUDE) + if ((outmask & GEOD_LONGITUDE) && plon2) *plon2 = lon2; - if (outmask & GEOD_AZIMUTH) + if ((outmask & GEOD_AZIMUTH) && pazi2) *pazi2 = azi2; - if (outmask & GEOD_DISTANCE) + if ((outmask & GEOD_DISTANCE) && ps12) *ps12 = s12; - if (outmask & GEOD_REDUCEDLENGTH) + if ((outmask & GEOD_REDUCEDLENGTH) && pm12) *pm12 = m12; if (outmask & GEOD_GEODESICSCALE) { if (pM12) *pM12 = M12; if (pM21) *pM21 = M21; } - if (outmask & GEOD_AREA) + if ((outmask & GEOD_AREA) && pS12) *pS12 = S12; return (flags & GEOD_ARCMODE) ? s12_a12 : sig12 / degree; diff --git a/src/pj_datum_set.c b/src/pj_datum_set.c index 5955ed5e..374beda2 100644 --- a/src/pj_datum_set.c +++ b/src/pj_datum_set.c @@ -61,7 +61,10 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef) /* find the end of the list, so we can add to it */ for (curr = pl; curr && curr->next ; curr = curr->next) {} - + + /* cannot happen in practice, but makes static analyzers happy */ + if( !curr ) return -1; + /* find the datum definition */ for (i = 0; (s = pj_datums[i].id) && strcmp(name, s) ; ++i) {} diff --git a/src/pj_gridcatalog.c b/src/pj_gridcatalog.c index c0194146..8777185b 100644 --- a/src/pj_gridcatalog.c +++ b/src/pj_gridcatalog.c @@ -260,7 +260,7 @@ PJ_GRIDINFO *pj_gc_findgrid( projCtx ctx, PJ_GridCatalog *catalog, int after, break; } - if( iEntry == catalog->entry_count ) + if( entry == NULL ) { if( grid_date ) *grid_date = 0.0; diff --git a/src/pj_init.c b/src/pj_init.c index 16408ebb..2d549317 100644 --- a/src/pj_init.c +++ b/src/pj_init.c @@ -67,6 +67,9 @@ static paralist *string_to_paralist (PJ_CONTEXT *ctx, char *definition) { c++; } + if( next == 0 ) + return 0; + /* Terminate list and return */ next->next = 0; return first; diff --git a/src/pj_param.c b/src/pj_param.c index 133f3ea6..b52ac940 100644 --- a/src/pj_param.c +++ b/src/pj_param.c @@ -131,17 +131,20 @@ PROJVALUE pj_param (projCtx ctx, paralist *pl, const char *opt) { /* Not found */ if (0==pl) { + /* Return value after the switch, so that the return path is */ + /* taken in all cases */ switch (type) { case 'b': case 'i': value.i = 0; - return value; + break; case 'd': case 'r': value.f = 0.; - return value; + break; case 's': value.s = 0; - return value; + break; } + return value; } /* Found parameter - now find its value */ |
