diff options
| author | Kristian Evers <kristianevers@gmail.com> | 2018-03-22 17:43:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-22 17:43:47 +0100 |
| commit | 1160207dd392504ce552d6efe42f820ccceaecd8 (patch) | |
| tree | f25efa240a7b90aa418fbca88069f421772f7e28 | |
| parent | 6fa838b290bd26eb68d20da49724d4fea32b9eb9 (diff) | |
| parent | ec494f12d10412d389733a196ec58a4d0c4beffa (diff) | |
| download | PROJ-1160207dd392504ce552d6efe42f820ccceaecd8.tar.gz PROJ-1160207dd392504ce552d6efe42f820ccceaecd8.zip | |
Merge pull request #887 from schwehr/float-cast-overflow
Handle nan float cast overflow in PJ_robin.c and nad_intr.c
| -rw-r--r-- | src/PJ_robin.c | 6 | ||||
| -rw-r--r-- | src/nad_intr.c | 9 | ||||
| -rw-r--r-- | src/pj_internal.c | 12 | ||||
| -rw-r--r-- | src/proj_internal.h | 2 |
4 files changed, 25 insertions, 4 deletions
diff --git a/src/PJ_robin.c b/src/PJ_robin.c index 7514b325..92aebfd3 100644 --- a/src/PJ_robin.c +++ b/src/PJ_robin.c @@ -1,4 +1,5 @@ #define PJ_LIB__ +#include "proj_internal.h" #include "proj.h" #include "projects.h" @@ -80,7 +81,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ double dphi; (void) P; - i = (int)floor((dphi = fabs(lp.phi)) * C1); + dphi = fabs(lp.phi); + i = pj_is_nan(lp.phi) ? -1 : (int)floor(dphi * C1); if( i < 0 ){ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return xy; @@ -115,7 +117,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ } } else { /* general problem */ /* in Y space, reduce to table interval */ - i = (int)floor(lp.phi * NODES); + i = pj_is_nan(lp.phi) ? -1 : (int)floor(lp.phi * NODES); if( i < 0 || i >= NODES ) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return lp; diff --git a/src/nad_intr.c b/src/nad_intr.c index b385410f..dc245831 100644 --- a/src/nad_intr.c +++ b/src/nad_intr.c @@ -1,6 +1,8 @@ /* Determine nad table correction value */ #define PJ_LIB__ +#include "proj_internal.h" #include "projects.h" + LP nad_intr(LP t, struct CTABLE *ct) { LP val, frct; @@ -10,8 +12,11 @@ nad_intr(LP t, struct CTABLE *ct) { long index; int in; - indx.lam = (int)floor(t.lam /= ct->del.lam); - indx.phi = (int)floor(t.phi /= ct->del.phi); + t.lam /= ct->del.lam; + indx.lam = pj_is_nan(t.lam) ? 0 : (int)floor(t.lam); + t.phi /= ct->del.phi; + indx.phi = pj_is_nan(t.phi) ? 0 : (int)floor(t.phi); + frct.lam = t.lam - indx.lam; frct.phi = t.phi - indx.phi; val.lam = val.phi = HUGE_VAL; diff --git a/src/pj_internal.c b/src/pj_internal.c index 61905259..9cbbf20a 100644 --- a/src/pj_internal.c +++ b/src/pj_internal.c @@ -443,3 +443,15 @@ void proj_log_func (PJ_CONTEXT *ctx, void *app_data, PJ_LOG_FUNCTION logf) { if (0!=logf) ctx->logger = logf; } + + +/*****************************************************************************/ +int pj_is_nan (double val) { +/****************************************************************************** + Returns 0 if not a NaN and non-zero if val is a NaN. + + Provides an equivalent to isnan(). +******************************************************************************/ + /* cppcheck-suppress duplicateExpression */ + return val != val; +} diff --git a/src/proj_internal.h b/src/proj_internal.h index 75893c33..b3843a59 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -130,6 +130,8 @@ void proj_fileapi_set (PJ *P, void *fileapi); const char * const *proj_get_searchpath(void); int proj_get_path_count(void); +int pj_is_nan (double val); + #ifdef __cplusplus } #endif |
