From 0ec59ca29500fad156c8f2dd6a96e13bb6595f88 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Wed, 6 Mar 2019 14:31:22 +0100 Subject: Make gie return non-zero exit code when file can't be opened --- src/apps/gie.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index abed11c0..e6b63d51 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -300,6 +300,20 @@ int main (int argc, char **argv) { return 1; } + for (i = 0; i < o->fargc; i++ ) { + FILE* f = fopen (o->fargv[i], "rt"); + if (f == nullptr) { + fprintf ( + T.fout, + "%sCannot open specified input file '%s' - bye!\n", + delim, + o->fargv[i] + ); + return 1; + } + fclose(f); + } + for (i = 0; i < o->fargc; i++) process_file (o->fargv[i]); @@ -370,8 +384,6 @@ static int another_failing_roundtrip (void) { } static int process_file (const char *fname) { - FILE *f; - F->lineno = F->next_lineno = F->level = 0; T.op_ok = T.total_ok = 0; T.op_ko = T.total_ko = 0; @@ -383,15 +395,8 @@ static int process_file (const char *fname) { return 0; } - f = fopen (fname, "rt"); - if (nullptr==f) { - if (T.verbosity > 0) { - fprintf (T.fout, "%sCannot open spec'd input file '%s' - bye!\n", delim, fname); - return 2; - } - errmsg (2, "Cannot open spec'd input file '%s' - bye!\n", fname); - } - F->f = f; + /* We have already tested in main that the file exists */ + F->f = fopen (fname, "rt"); if (T.verbosity > 0) fprintf (T.fout, "%sReading file '%s'\n", delim, fname); @@ -405,7 +410,7 @@ static int process_file (const char *fname) { } } - fclose (f); + fclose (F->f); F->lineno = F->next_lineno = 0; T.grand_ok += T.total_ok; -- cgit v1.2.3 From 0cd621da5791a99528f6a5fe892c659cab3bda23 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sat, 9 Mar 2019 10:30:11 +0100 Subject: Allow gie to use proj_create_crs_to_crs (#1314) The commands crs_src and crs_dst are introduced to allow operation initialization with proj_create_crs_to_crs. This has the benefit of using proj.db to select the proper operation. Additionally axis order is respected for the coordinate systems that are tested. This is beneficial when running the GIGS test suite for instance. --- src/apps/gie.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index e6b63d51..5407c0ba 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -148,7 +148,7 @@ static ffio *ffio_destroy (ffio *G); static ffio *ffio_create (const char **tags, size_t n_tags, size_t max_record_size); static const char *gie_tags[] = { - "", "operation", "use_proj4_init_rules", + "", "operation", "crs_src", "crs_dst", "use_proj4_init_rules", "accept", "expect", "roundtrip", "banner", "verbose", "direction", "tolerance", "ignore", "require_grid", "echo", "skip", "" }; @@ -175,6 +175,8 @@ static const char *err_const_from_errno (int err); typedef struct { char operation[MAX_OPERATION+1]; + char crs_dst[MAX_OPERATION+1]; + char crs_src[MAX_OPERATION+1]; PJ *P; PJ_COORD a, b, c, e; PJ_DIRECTION dir; @@ -607,6 +609,65 @@ either a conversion or a transformation) return 0; } +static int crs_to_crs_operation() { + T.op_id++; + T.operation_lineno = F->lineno; + + if (T.verbosity > 1) { + char buffer[80]; + finish_previous_operation (F->args); + snprintf(buffer, 80, "%-36.36s -> %-36.36s", T.crs_src, T.crs_dst); + banner (buffer); + } + + T.op_ok = 0; + T.op_ko = 0; + T.op_skip = 0; + T.skip_test = 0; + + direction ("forward"); + tolerance ("0.5 mm"); + ignore ("pjd_err_dont_skip"); + + proj_errno_reset (T.P); + + if (T.P) + proj_destroy (T.P); + proj_errno_reset (nullptr); + proj_context_use_proj4_init_rules(nullptr, T.use_proj4_init_rules); + + + T.P = proj_create_crs_to_crs(nullptr, T.crs_src, T.crs_dst, nullptr); + + strcpy(T.crs_src, ""); + strcpy(T.crs_dst, ""); + return 0; +} + +static int crs_src(const char *args) { + strncpy (&(T.crs_src[0]), F->args, MAX_OPERATION); + T.crs_src[MAX_OPERATION] = '\0'; + (void) args; + + if (strcmp(T.crs_src, "") != 0 && strcmp(T.crs_dst, "") != 0) { + crs_to_crs_operation(); + } + + return 0; +} + +static int crs_dst(const char *args) { + strncpy (&(T.crs_dst[0]), F->args, MAX_OPERATION); + T.crs_dst[MAX_OPERATION] = '\0'; + (void) args; + + if (strcmp(T.crs_src, "") != 0 && strcmp(T.crs_dst, "") != 0) { + crs_to_crs_operation(); + } + + return 0; +} + static PJ_COORD torad_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) { size_t i, n; const char *axis = "enut"; @@ -1000,6 +1061,8 @@ static int dispatch (const char *cmnd, const char *args) { if (T.skip) return SKIP; if (0==strcmp (cmnd, "operation")) return operation ((char *) args); + if (0==strcmp (cmnd, "crs_src")) return crs_src (args); + if (0==strcmp (cmnd, "crs_dst")) return crs_dst (args); if (T.skip_test) { if (0==strcmp (cmnd, "expect")) return another_skip(); -- cgit v1.2.3 From 6c22035b270aa46f03e6252cd552be14d170e501 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 26 Mar 2019 14:12:31 +0100 Subject: gie.cpp: silence Coverity CID 193520 --- src/apps/gie.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 5407c0ba..a84e77ab 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -249,6 +249,7 @@ int main (int argc, char **argv) { T.ignore = 5555; /* Error code that will not be issued by proj_create() */ T.use_proj4_init_rules = FALSE; + /* coverity[tainted_data] */ o = opt_parse (argc, argv, "hlvq", "o", longflags, longkeys); if (nullptr==o) return 0; -- cgit v1.2.3 From 095d2204f8bb05d172936aebbb1e9e44852c049f Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Fri, 29 Mar 2019 19:17:37 +0000 Subject: Remove duplicate instances of #include "proj_internal.h" Introduced by "Merge projects.h into proj_internal.h" 8ab6f683. --- src/apps/gie.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index a84e77ab..47211aa8 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -117,7 +117,6 @@ Thomas Knudsen, thokn@sdfe.dk, 2017-10-01/2017-10-08 #include "proj_internal.h" #include "proj_math.h" #include "proj_strtod.h" -#include "proj_internal.h" #include "optargpm.h" -- cgit v1.2.3 From 20300c1fd5b35bf1d577a3726f02940d02c73f54 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Tue, 2 Apr 2019 13:30:33 +0200 Subject: Make sure that ISO19111 C++ code sets pj_errno on errors --- src/apps/gie.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 47211aa8..912113b4 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -1151,6 +1151,7 @@ static const struct errno_vs_err_const lookup[] = { {"pjd_err_invalid_arg" , -58}, {"pjd_err_inconsistent_unit" , -59}, {"pjd_err_mutually_exclusive_args" , -60}, + {"pjd_err_generic_error" , -61}, {"pjd_err_dont_skip" , 5555}, {"pjd_err_unknown" , 9999}, {"pjd_err_enomem" , ENOMEM}, -- cgit v1.2.3 From c1f5b5105065d6cb9f4e547b6b79c83357f1d759 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 2 Apr 2019 23:04:37 +0200 Subject: gie: fix tolerance checking When comparing expected result with got result, in the case the distance computation returns NaN, gie incorrectly considered the test to be OK. Adapt / comment out a few broken tests revealed after that fix. --- src/apps/gie.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 47211aa8..03dc1556 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -1005,7 +1005,8 @@ Tell GIE what to expect, when transforming the ACCEPTed input else d = proj_xyz_dist (co, ce); - if (d > T.tolerance) + // Test written like that to handle NaN + if (!(d <= T.tolerance)) return expect_message (d, args); succs++; -- cgit v1.2.3 From 70ed3efe60718be74d73d92ec2d121e2de268e53 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 4 Apr 2019 22:36:00 +0200 Subject: Reject negative e parameter to avoid division by zero Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14044 Credit to OSS Fuzz --- src/apps/gie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index f0f7968f..5a86ebb7 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -1097,7 +1097,7 @@ static const struct errno_vs_err_const lookup[] = { {"pjd_err_no_colon_in_init_string" , -3}, {"pjd_err_proj_not_named" , -4}, {"pjd_err_unknown_projection_id" , -5}, - {"pjd_err_eccentricity_is_one" , -6}, + {"pjd_err_invalid_eccentricity" , -6}, {"pjd_err_unknown_unit_id" , -7}, {"pjd_err_invalid_boolean_param" , -8}, {"pjd_err_unknown_ellp_param" , -9}, -- cgit v1.2.3 From 96af6dbf69dd38421916438702be80f73276d879 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 5 May 2019 20:28:59 +0200 Subject: geos: avoid division by zero Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14602 Credit to OSS Fuzz --- src/apps/gie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/apps/gie.cpp') diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 5a86ebb7..2f401984 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -1121,7 +1121,7 @@ static const struct errno_vs_err_const lookup[] = { {"pjd_err_w_or_m_zero_or_less" , -27}, {"pjd_err_lsat_not_in_range" , -28}, {"pjd_err_path_not_in_range" , -29}, - {"pjd_err_h_less_than_zero" , -30}, + {"pjd_err_invalid_h" , -30}, {"pjd_err_k_less_than_zero" , -31}, {"pjd_err_lat_1_or_2_zero_or_90" , -32}, {"pjd_err_lat_0_or_alpha_eq_90" , -33}, -- cgit v1.2.3