aboutsummaryrefslogtreecommitdiff
path: root/src/pj_gridinfo.c
diff options
context:
space:
mode:
authorAaron Puchert <aaron.puchert@sap.com>2017-10-20 12:58:10 +0200
committerAaron Puchert <aaron.puchert@sap.com>2017-11-27 14:57:42 +0100
commit3175dce5fcec54fef6299cc8b595d84db5b29cf4 (patch)
tree0c82ae4f4afa9eb44893e1bd7d1f9a884459e2d9 /src/pj_gridinfo.c
parent1f48f4c333bfe135296d3be643ef4981dc401c38 (diff)
downloadPROJ-3175dce5fcec54fef6299cc8b595d84db5b29cf4.tar.gz
PROJ-3175dce5fcec54fef6299cc8b595d84db5b29cf4.zip
Replace some asserts by compile-time assertions
Decisions regarding the size of certain types are always made at compile time, hence this is where the assertion should take place. If the assertions fail, there is now a compiler error.
Diffstat (limited to 'src/pj_gridinfo.c')
-rw-r--r--src/pj_gridinfo.c78
1 files changed, 12 insertions, 66 deletions
diff --git a/src/pj_gridinfo.c b/src/pj_gridinfo.c
index ad4695ca..9b9a8d82 100644
--- a/src/pj_gridinfo.c
+++ b/src/pj_gridinfo.c
@@ -28,21 +28,12 @@
#define PJ_LIB__
-#include <projects.h>
+#include "proj_internal.h"
+#include "projects.h"
#include <string.h>
#include <math.h>
#include <errno.h>
-#ifdef _WIN32_WCE
-/* assert.h includes all Windows API headers and causes 'LP' name clash.
- * Here assert we disable assert() for Windows CE.
- * TODO - mloskot: re-implement porting friendly assert
- */
-# define assert(exp) ((void)0)
-#else
-# include <assert.h>
-#endif /* _WIN32_WCE */
-
/************************************************************************/
/* swap_words() */
/* */
@@ -431,23 +422,8 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
int num_subfiles, subfile;
int must_swap;
- assert( sizeof(int) == 4 );
- assert( sizeof(double) == 8 );
-#ifdef _MSC_VER
-#pragma warning( push )
-/* disable conditional expression is constant */
-#pragma warning( disable : 4127 )
-#endif
- if( sizeof(int) != 4 || sizeof(double) != 8 )
-#ifdef _MSC_VER
-#pragma warning( pop )
-#endif
- {
- pj_log( ctx, PJ_LOG_ERROR,
- "basic types of inappropraiate size in pj_gridinfo_init_ntv2()" );
- pj_ctx_set_errno( ctx, -38 );
- return 0;
- }
+ STATIC_ASSERT( sizeof(pj_int32) == 4 );
+ STATIC_ASSERT( sizeof(double) == 8 );
/* -------------------------------------------------------------------- */
/* Read the overview header. */
@@ -541,8 +517,8 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
ct->del.lam = *((double *) (header+9*16+8));
ct->del.phi = *((double *) (header+8*16+8));
- ct->lim.lam = (int) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1;
- ct->lim.phi = (int) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1;
+ ct->lim.lam = (pj_int32) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1;
+ ct->lim.phi = (pj_int32) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1;
pj_log( ctx, PJ_LOG_DEBUG_MINOR,
"NTv2 %s %dx%d: LL=(%.9g,%.9g) UR=(%.9g,%.9g)\n",
@@ -669,23 +645,8 @@ static int pj_gridinfo_init_ntv1( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi )
struct CTABLE *ct;
LP ur;
- assert( sizeof(int) == 4 );
- assert( sizeof(double) == 8 );
-#ifdef _MSC_VER
-#pragma warning( push )
-/* disable conditional expression is constant */
-#pragma warning( disable : 4127 )
-#endif
- if( sizeof(int) != 4 || sizeof(double) != 8 )
-#ifdef _MSC_VER
-#pragma warning( pop )
-#endif
- {
- pj_log( ctx, PJ_LOG_ERROR,
- "basic types of inappropraiate size in nad_load_ntv1()" );
- pj_ctx_set_errno( ctx, -38 );
- return 0;
- }
+ STATIC_ASSERT( sizeof(pj_int32) == 4 );
+ STATIC_ASSERT( sizeof(double) == 8 );
/* -------------------------------------------------------------------- */
/* Read the header. */
@@ -734,8 +695,8 @@ static int pj_gridinfo_init_ntv1( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi )
ur.phi = *((double *) (header+40));
ct->del.lam = *((double *) (header+104));
ct->del.phi = *((double *) (header+88));
- ct->lim.lam = (int) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1;
- ct->lim.phi = (int) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1;
+ ct->lim.lam = (pj_int32) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1;
+ ct->lim.phi = (pj_int32) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1;
pj_log( ctx, PJ_LOG_DEBUG_MINOR,
"NTv1 %dx%d: LL=(%.9g,%.9g) UR=(%.9g,%.9g)",
@@ -769,23 +730,8 @@ static int pj_gridinfo_init_gtx( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi )
double xorigin,yorigin,xstep,ystep;
int rows, columns;
- assert( sizeof(int) == 4 );
- assert( sizeof(double) == 8 );
-#ifdef _MSC_VER
-#pragma warning( push )
-/* disable conditional expression is constant */
-#pragma warning( disable : 4127 )
-#endif
- if( sizeof(int) != 4 || sizeof(double) != 8 )
-#ifdef _MSC_VER
-#pragma warning( pop )
-#endif
- {
- pj_log( ctx, PJ_LOG_ERROR,
- "basic types of inappropraiate size in nad_load_gtx()" );
- pj_ctx_set_errno( ctx, -38 );
- return 0;
- }
+ STATIC_ASSERT( sizeof(pj_int32) == 4 );
+ STATIC_ASSERT( sizeof(double) == 8 );
/* -------------------------------------------------------------------- */
/* Read the header. */