Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nan float cast overflow in PJ_robin.c and nad_intr.c #887

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/PJ_robin.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define PJ_LIB__
#include "proj_internal.h"
#include "proj.h"
#include "projects.h"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/nad_intr.c
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/pj_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down