GeoConvHelper::~GeoConvHelper() { #ifdef PROJ_API_FILE if (myProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR proj_destroy(myProjection); #else pj_free(myProjection); #endif } if (myInverseProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR proj_destroy(myInverseProjection); #else pj_free(myInverseProjection); #endif } if (myGeoProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR proj_destroy(myGeoProjection); #else pj_free(myGeoProjection); #endif } #endif }
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; T.op_skip = T.total_skip = 0; if (T.skip) { proj_destroy (T.P); T.P = nullptr; 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; if (T.verbosity > 0) fprintf (T.fout, "%sReading file '%s'\n", delim, fname); T.curr_file = fname; while (get_inp(F)) { if (SKIP==dispatch (F->tag, F->args)) { proj_destroy (T.P); T.P = nullptr; return 0; } } fclose (f); F->lineno = F->next_lineno = 0; T.grand_ok += T.total_ok; T.grand_ko += T.total_ko; T.grand_skip += T.grand_skip; if (T.verbosity > 0) { fprintf (T.fout, "%stotal: %2d tests succeeded, %2d tests skipped, %2d tests %s\n", delim, T.total_ok, T.total_skip, T.total_ko, T.total_ko? "FAILED!": "failed."); } if (F->level==0) return errmsg (-3, "File '%s':Missing '<gie>' cmnd - bye!\n", fname); if (F->level && F->level%2) return errmsg (-4, "File '%s':Missing '</gie>' cmnd - bye!\n", fname); return 0; }
static void GetNameFromDatabase(GTIF* gtif, const char* pszCode, PJ_CATEGORY category, char* pszOut, size_t nOutSize) { PJ* obj = proj_create_from_database( gtif->pj_context, "EPSG", pszCode, category, FALSE, NULL); if( obj ) { const char* pszName = proj_get_name(obj); if( pszName ) { size_t nToCopy = MIN(strlen(pszName), nOutSize - 1); memcpy(pszOut, pszName, nToCopy); pszOut[nToCopy] = 0; } proj_destroy(obj); } else { pszOut[0] = 0; } }
PJ *proj_create (PJ_CONTEXT *ctx, const char *definition) { /************************************************************************************** Create a new PJ object in the context ctx, using the given definition. If ctx==0, the default context is used, if definition==0, or invalid, a null-pointer is returned. The definition may use '+' as argument start indicator, as in "+proj=utm +zone=32", or leave it out, as in "proj=utm zone=32". It may even use free formatting "proj = utm; zone =32 ellps= GRS80". Note that the semicolon separator is allowed, but not required. **************************************************************************************/ PJ *P; char *args, **argv; size_t argc, n; int ret; if (0==ctx) ctx = pj_get_default_ctx (); /* Make a copy that we can manipulate */ n = strlen (definition); args = (char *) malloc (n + 1); if (0==args) return 0; strcpy (args, definition); argc = pj_trim_argc (args); if (argc==0) { pj_dealloc (args); return 0; } argv = pj_trim_argv (argc, args); /* ...and let pj_init_ctx do the hard work */ P = pj_init_ctx (ctx, (int) argc, argv); pj_dealloc (argv); pj_dealloc (args); /* Support cs2cs-style modifiers */ ret = cs2cs_emulation_setup (P); if (0==ret) return proj_destroy (P); return P; }
static int operation (char *args) { /***************************************************************************** Define the operation to apply to the input data (in ISO 19100 lingo, an operation is the general term describing something that can be either a conversion or a transformation) ******************************************************************************/ T.op_id++; T.operation_lineno = F->lineno; strncpy (&(T.operation[0]), F->args, MAX_OPERATION); T.operation[MAX_OPERATION] = '\0'; if (T.verbosity > 1) { finish_previous_operation (F->args); banner (args); } 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 (nullptr, F->args); /* Checking that proj_create succeeds is first done at "expect" time, */ /* since we want to support "expect"ing specific error codes */ return 0; }
static PJ *destructor (PJ *P, int errlev) { int i; if (nullptr==P) return nullptr; if (nullptr==P->opaque) return pj_default_destructor (P, errlev); /* Deallocate each pipeline step, then pipeline array */ if (nullptr!=static_cast<struct pj_opaque*>(P->opaque)->pipeline) for (i = 0; i < static_cast<struct pj_opaque*>(P->opaque)->steps; i++) proj_destroy (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i+1]); pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->pipeline); pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->argv); pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->current_argv); for (i=0; i<4; i++) delete static_cast<struct pj_opaque*>(P->opaque)->stack[i]; return pj_default_destructor(P, errlev); }
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { if( len > 1000 ) { #ifdef STANDALONE fprintf(stderr, "Input too large\n"); #endif return 0; } /* We expect the blob to be 2 lines: */ /* source_string\ndestination_string */ char* buf_dup = (char*)malloc(len+1); memcpy(buf_dup, buf, len); buf_dup[len] = 0; char* first_line = buf_dup; char* first_newline = strchr(first_line, '\n'); if( !first_newline ) { free(buf_dup); return 0; } first_newline[0] = 0; char* second_line = first_newline + 1; #ifdef STANDALONE fprintf(stderr, "src=%s\n", first_line); fprintf(stderr, "dst=%s\n", second_line); #endif proj_destroy( proj_create_crs_to_crs(nullptr, first_line, second_line, nullptr)); free(buf_dup); pj_gc_unloadall(pj_get_default_ctx()); pj_deallocate_grids(); return 0; }
GeoConvHelper& GeoConvHelper::operator=(const GeoConvHelper& orig) { myProjString = orig.myProjString; myOffset = orig.myOffset; myProjectionMethod = orig.myProjectionMethod; myOrigBoundary = orig.myOrigBoundary; myConvBoundary = orig.myConvBoundary; myGeoScale = orig.myGeoScale; myCos = orig.myCos; mySin = orig.mySin; myUseInverseProjection = orig.myUseInverseProjection; myFlatten = orig.myFlatten; #ifdef PROJ_API_FILE if (myProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR proj_destroy(myProjection); #else pj_free(myProjection); #endif myProjection = nullptr; } if (myInverseProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR proj_destroy(myInverseProjection); #else pj_free(myInverseProjection); #endif myInverseProjection = nullptr; } if (myGeoProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR proj_destroy(myGeoProjection); #else pj_free(myGeoProjection); #endif myGeoProjection = nullptr; } if (orig.myProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR myProjection = proj_create(PJ_DEFAULT_CTX, orig.myProjString.c_str()); #else myProjection = pj_init_plus(orig.myProjString.c_str()); #endif } if (orig.myInverseProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR myInverseProjection = orig.myInverseProjection; #else myInverseProjection = pj_init_plus(pj_get_def(orig.myInverseProjection, 0)); #endif } if (orig.myGeoProjection != nullptr) { #ifdef PROJ_VERSION_MAJOR myGeoProjection = orig.myGeoProjection; #else myGeoProjection = pj_init_plus(pj_get_def(orig.myGeoProjection, 0)); #endif } #endif return *this; }