From 5178303e1997d582dd5c541dc76f12b1a5999f68 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 25 Nov 2024 01:02:12 +0100 Subject: [PATCH 1/2] Fix lots of Coverity Scan warnings in frmts/hdf4/hdf-eos --- frmts/hdf4/hdf-eos/EHapi.c | 131 ++++--- frmts/hdf4/hdf-eos/GDapi.c | 595 +++++++++++++++++++----------- frmts/hdf4/hdf-eos/SWapi.c | 736 +++++++++++++++++++++++-------------- 3 files changed, 907 insertions(+), 555 deletions(-) diff --git a/frmts/hdf4/hdf-eos/EHapi.c b/frmts/hdf4/hdf-eos/EHapi.c index 46f1d4bb17fd..3da68c6a9e75 100644 --- a/frmts/hdf4/hdf-eos/EHapi.c +++ b/frmts/hdf4/hdf-eos/EHapi.c @@ -10,9 +10,9 @@ /* Copyright (C) 1996 Hughes and Applied Research Corporation -Permission to use, modify, and distribute this software and its documentation -for any purpose without fee is hereby granted, provided that the above -copyright notice appear in all copies and that both that copyright notice and +Permission to use, modify, and distribute this software and its documentation +for any purpose without fee is hereby granted, provided that the above +copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. */ @@ -30,10 +30,10 @@ static int32 *EHXfidTable = NULL; static int32 *EHXsdTable = NULL; /* define a macro for the string size of the utility strings and some dimension - list strings. The value in previous versions of this code may not be - enough in some cases. The length now is 512 which seems to be more than + list strings. The value in previous versions of this code may not be + enough in some cases. The length now is 512 which seems to be more than enough to hold larger strings. */ - + #define UTLSTR_MAX_SIZE 512 #define UTLSTRSIZE 32000 @@ -198,7 +198,7 @@ EHopen(const char *filename, intn access) /* ------------------------- */ metabuf = (char *) calloc(32000, 1); if(metabuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHopen", __FILE__, __LINE__); return(-1); } @@ -237,7 +237,7 @@ EHopen(const char *filename, intn access) /* Get HDF file ID */ /* --------------- */ #ifndef _PGS_OLDNFS -/* The following loop around the function Hopen is intended to deal with the NFS cache +/* The following loop around the function Hopen is intended to deal with the NFS cache problem when opening file fails with errno = 150 or 151. When NFS cache is updated, this part of change is no longer necessary. 10/18/1999 */ retryCount = 0; @@ -271,7 +271,7 @@ EHopen(const char *filename, intn access) { /* Set HDFEOS version number in file */ /* --------------------------------- */ - + attrIndex = SDfindattr(sdInterfaceID, "HDFEOSVersion"); if (attrIndex == -1) { @@ -294,7 +294,7 @@ EHopen(const char *filename, intn access) { metabuf = (char *) calloc(32000, 1); if(metabuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHopen", __FILE__, __LINE__); return(-1); } @@ -344,7 +344,7 @@ EHopen(const char *filename, intn access) /* Get HDF file ID */ /* --------------- */ #ifndef _PGS_OLDNFS -/* The following loop around the function Hopen is intended to deal with the NFS cache +/* The following loop around the function Hopen is intended to deal with the NFS cache problem when opening file fails with errno = 150 or 151. When NFS cache is updated, this part of change is no longer necessary. 10/18/1999 */ retryCount = 0; @@ -371,10 +371,7 @@ EHopen(const char *filename, intn access) fid = -1; status = -1; HEpush(DFE_FNF, "EHopen", __FILE__, __LINE__); - strcpy(errbuf, "\""); - strcat(errbuf, filename); - strcat(errbuf, "\" (opened for READONLY access)"); - strcat(errbuf, " does not exist."); + snprintf(errbuf, sizeof(errbuf), "\"%s\" (opened for READONLY access) does not exist.", filename); HEreport("%s\n", errbuf); } else { @@ -386,7 +383,7 @@ EHopen(const char *filename, intn access) /* ------------------------- */ if (sdInterfaceID != -1) { - + /* Set open access to read-only */ /* ---------------------------- */ acs = 0; @@ -1012,13 +1009,13 @@ EHstrwithin(const char *target, const char *search, const char delim) /* ----------------------------------------- */ ptr = (char **) calloc(nentries, sizeof(char *)); if(ptr == NULL) - { + { HEpush(DFE_NOSPACE,"EHstrwithin", __FILE__, __LINE__); return(-1); } slen = (int32 *) calloc(nentries, sizeof(int32)); if(slen == NULL) - { + { HEpush(DFE_NOSPACE,"EHstrwithin", __FILE__, __LINE__); free(ptr); return(-1); @@ -1200,13 +1197,13 @@ EHgetid(int32 fid, int32 vgid, const char *objectname, intn code, /* ---------------------------------- */ tags = (int32 *) malloc(sizeof(int32) * nObjects); if(tags == NULL) - { + { HEpush(DFE_NOSPACE,"EHgetid", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * nObjects); if(refs == NULL) - { + { HEpush(DFE_NOSPACE,"EHgetid", __FILE__, __LINE__); free(tags); return(-1); @@ -1332,7 +1329,7 @@ EHrevflds(const char *dimlist, char *revdimlist) /* ------------------------------ */ tempdimlist = (char *) malloc(strlen(dimlist) + 1); if(tempdimlist == NULL) - { + { HEpush(DFE_NOSPACE,"EHrevflds", __FILE__, __LINE__); return(-1); } @@ -1348,14 +1345,14 @@ EHrevflds(const char *dimlist, char *revdimlist) /* ----------------------------------------- */ ptr = (char **) calloc(nentries, sizeof(char *)); if(ptr == NULL) - { + { HEpush(DFE_NOSPACE,"EHrevflds", __FILE__, __LINE__); free(tempdimlist); return(-1); } slen = (int32 *) calloc(nentries, sizeof(int32)); if(slen == NULL) - { + { HEpush(DFE_NOSPACE,"EHrevflds", __FILE__, __LINE__); free(ptr); free(tempdimlist); @@ -1567,13 +1564,13 @@ EHmetalist(const char *instring, char *outstring) /* ----------------------------------------- */ ptr = (char **) calloc(nentries, sizeof(char *)); if(ptr == NULL) - { + { HEpush(DFE_NOSPACE,"EHmetalist", __FILE__, __LINE__); return(-1); } slen = (int32 *) calloc(nentries, sizeof(int32)); if(slen == NULL) - { + { HEpush(DFE_NOSPACE,"EHmetalist", __FILE__, __LINE__); free(ptr); return(-1); @@ -1699,7 +1696,7 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode char *metaptr; /* Metadata pointer */ char *prevmetaptr;/* Previous position of metadata pointer */ char *ptr[8]; /* String pointer array (for dim map parsing) */ - char type[32]; /* Number type descriptor string */ + char type[32] = {0}; /* Number type descriptor string */ char *metaArr[2]; /* Array of metadata positions */ char *colon; /* Colon position */ char *colon2; /* 2nd colon position */ @@ -1712,14 +1709,14 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* ---------------------------------- */ utlstr = (char *) calloc(UTLSTRSIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"EHinsertmeta", __FILE__, __LINE__); return(-1); } utlstr2 = (char *) calloc(UTLSTRSIZE, sizeof(char)); if(utlstr2 == NULL) - { + { HEpush(DFE_NOSPACE,"EHinsertmeta", __FILE__, __LINE__); free(utlstr); return(-1); @@ -1752,7 +1749,7 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* ----------------------------------------------------- */ metabuf = (char *) calloc(32000 * nmeta, 1); if(metabuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHinsertmeta", __FILE__, __LINE__); free(utlstr); free(utlstr2); @@ -2005,9 +2002,14 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* Find colon (parse off field name) */ /* --------------------------------- */ colon = strchr(metastr, ':'); + if (colon == NULL) + { + free(utlstr); + free(utlstr2); + return -1; + } *colon = 0; - /* Search for next colon (compression and/or tiling parameters) */ /* ------------------------------------------------------------ */ colon2 = strchr(colon + 1, ':'); @@ -2067,9 +2069,14 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* Find colon (parse off field name) */ /* --------------------------------- */ colon = strchr(metastr, ':'); + if (colon == NULL) + { + free(utlstr); + free(utlstr2); + return -1; + } *colon = 0; - /* Search for next colon (compression and/or tiling parameters) */ /* ------------------------------------------------------------ */ colon2 = strchr(colon + 1, ':'); @@ -2129,13 +2136,17 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* Find colon (parse off merged fieldname) */ /* --------------------------------------- */ colon = strchr(metastr, ':'); - + if (colon == NULL) + { + free(utlstr); + free(utlstr2); + return -1; + } + *colon = 0; /* Make metadata string list from field list */ /* ----------------------------------------- */ EHmetalist(colon + 1, utlstr2); - *colon = 0; - /* Build metadata entry string */ /* --------------------------- */ @@ -2183,9 +2194,14 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* Find colon (parse off point field name) */ /* --------------------------------------- */ colon = strchr(metastr, ':'); + if (colon == NULL) + { + free(utlstr); + free(utlstr2); + return -1; + } *colon = 0; - /* Find beginning and ending of metadata section */ /* --------------------------------------------- */ strcpy(utlstr, "\t\t\t\tLevelName=\""); @@ -2238,15 +2254,25 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* Find colon (parse off parent/child level names from link field) */ /* --------------------------------------------------------------- */ colon = strchr(metastr, ':'); + if (colon == NULL) + { + free(utlstr); + free(utlstr2); + return -1; + } *colon = 0; - /* Find slash (divide parent and child levels) */ /* ------------------------------------------- */ slash = strchr(metastr, '/'); + if (slash == NULL) + { + free(utlstr); + free(utlstr2); + return -1; + } *slash = 0; - /* Build metadata entry string */ /* --------------------------- */ snprintf(utlstr, UTLSTRSIZE, "%s%d%s%s%s%s%s%s%s%d%s", @@ -2315,7 +2341,7 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode /* ------------------------------------------------------ */ metabuf = (char *) realloc((void *) metabuf, 32000 * (nmeta + 1)); if(metabuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHinsertmeta", __FILE__, __LINE__); free(utlstr); free(utlstr2); @@ -2434,6 +2460,11 @@ EHgetmetavalue(char *metaptrs[], const char *parameter, char *retstr) /* Find newline "\n" character */ /* --------------------------- */ newline = strchr(metaptrs[0], '\n'); + if (newline == NULL) + { + retstr[0] = 0; + return -1; + } /* Copy from "=" to "\n" (exclusive) into return string */ /* ---------------------------------------------------- */ @@ -2511,9 +2542,9 @@ EHmetagroup(int32 sdInterfaceID, const char *structname, const char *structcode, /* ---------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE,sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"EHEHmetagroup", __FILE__, __LINE__); - + return( NULL); } /* Determine number of structural metadata "sections" */ @@ -2542,14 +2573,14 @@ EHmetagroup(int32 sdInterfaceID, const char *structname, const char *structcode, /* Allocate space for metadata (in units of 32000 bytes) */ /* ----------------------------------------------------- */ metabuf = (char *) calloc(32000 * nmeta, 1); - + if(metabuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHmetagroup", __FILE__, __LINE__); free(utlstr); return(metabuf); } - + /* Read structural metadata */ /* ------------------------ */ @@ -2730,11 +2761,11 @@ EHfillfld(int32 sdid, int32 rank, CPL_UNUSED int32 truerank, int32 size, int32 o /* -------------------- */ fillbuf = (char *) malloc(totN * size); if(fillbuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHfillfld", __FILE__, __LINE__); return(-1); } - + /* Fill buffer with fill value */ /* --------------------------- */ @@ -2770,7 +2801,7 @@ EHfillfld(int32 sdid, int32 rank, CPL_UNUSED int32 truerank, int32 size, int32 o /* -------------------- */ fillbuf = (char *) malloc(planeN * size * n); if(fillbuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHfillfld", __FILE__, __LINE__); return(-1); } @@ -2825,7 +2856,7 @@ EHfillfld(int32 sdid, int32 rank, CPL_UNUSED int32 truerank, int32 size, int32 o /* -------------------- */ fillbuf = (char *) malloc(dims[rank - 1] * size * n); if(fillbuf == NULL) - { + { HEpush(DFE_NOSPACE,"EHfillfld", __FILE__, __LINE__); return(-1); } @@ -2935,7 +2966,7 @@ EHbisect(float64(*func) (float64[]), float64 funcParms[], int32 nParms, /* -------------------------------------- */ parms = (float64 *) calloc(nParms + 1, sizeof(float64)); if(parms == NULL) - { + { HEpush(DFE_NOSPACE, "EHbisect", __FILE__, __LINE__); return(-1); } @@ -3272,13 +3303,13 @@ EHattrcat(int32 fid, int32 attrVgrpID, char *attrnames, int32 * strbufsize) /* ------------------------------------------- */ tags = (int32 *) malloc(sizeof(int32) * nObjects); if(tags == NULL) - { + { HEpush(DFE_NOSPACE,"EHattrcat", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * nObjects); if(refs == NULL) - { + { HEpush(DFE_NOSPACE,"EHattrcat", __FILE__, __LINE__); free(tags); return(-1); diff --git a/frmts/hdf4/hdf-eos/GDapi.c b/frmts/hdf4/hdf-eos/GDapi.c index 1a8be985d47b..6ff94e30836c 100644 --- a/frmts/hdf4/hdf-eos/GDapi.c +++ b/frmts/hdf4/hdf-eos/GDapi.c @@ -10,9 +10,9 @@ /* Copyright (C) 1996 Hughes and Applied Research Corporation -Permission to use, modify, and distribute this software and its documentation -for any purpose without fee is hereby granted, provided that the above -copyright notice appear in all copies and that both that copyright notice and +Permission to use, modify, and distribute this software and its documentation +for any purpose without fee is hereby granted, provided that the above +copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. */ /***************************************************************************** @@ -35,53 +35,53 @@ Jan 15, 2003 Abe Taaheri Modified for generalization of EASE Grid. Jun 05, 2003 Bruce Beaumont / Abe Taaheri Fixed SQUARE definition. - Added static projection number/name translation + Added static projection number/name translation Added projection table lookup in GDdefproj. Removed projection table from GDdefproj Added projection table lookup in GDprojinfo Removed projection table from GDprojinfo Added cast for compcode in call to SDsetcompress in GDdeffield to avoid compiler errors - Removed declaration for unused variable endptr + Removed declaration for unused variable endptr in GDSDfldsrch Removed initialization code for unused variables in GDSDfldsrch - Removed declarations for unused variables - BCEA_scale, r0, s0, xMtr0, xMtr1, yMtr0, + Removed declarations for unused variables + BCEA_scale, r0, s0, xMtr0, xMtr1, yMtr0, and yMtr1 in GDll2ij Removed initialization code for unused variables in GDll2ij - Added code in GEO projection handling to allow + Added code in GEO projection handling to allow map to span dateline in GDll2ij - Changed "for each point" loop in GDll2ij to - return -2147483648.0 for xVal and yVal if - for_trans returned an error instead of + Changed "for each point" loop in GDll2ij to + return -2147483648.0 for xVal and yVal if + for_trans returned an error instead of returning an error to the caller (Note: MAXLONG is defined as 2147483647.0 in function cproj.c of GCTP) - Added code in GDij2ll to use for_trans to - translate the BCEA corner points from packed + Added code in GDij2ll to use for_trans to + translate the BCEA corner points from packed degrees to meters - Removed declarations for unused variables - BCEA_scale, r0, s0, xMtr, yMtr, epsilon, - beta, qp_cea, kz_cea, eccen, eccen_sq, - phi1, sinphi1, cosphi1, lon, lat, xcor, + Removed declarations for unused variables + BCEA_scale, r0, s0, xMtr, yMtr, epsilon, + beta, qp_cea, kz_cea, eccen, eccen_sq, + phi1, sinphi1, cosphi1, lon, lat, xcor, ycor, and nlatlon from GDij2ll Removed initialization code for unused variables in GDij2ll - Added declarations for xMtr0, yMtr0, xMtr1, and + Added declarations for xMtr0, yMtr0, xMtr1, and yMtr1 in GDij2ll Added special-case code for BCEA - Changed "for each point" loop in GDij2ll to - return PGSd_GCT_IN_ERROR (1.0e51) for - longitude and latitude values if inv_trans - returned an error instead of return an error + Changed "for each point" loop in GDij2ll to + return PGSd_GCT_IN_ERROR (1.0e51) for + longitude and latitude values if inv_trans + returned an error instead of return an error to the caller - Removed declaration for unused variable ii in + Removed declaration for unused variable ii in GDgetpixvalues - Removed declaration for unused variable + Removed declaration for unused variable numTileDims in GDtileinfo - Added error message and error return at the + Added error message and error return at the end of GDll2mm_cea Added return statement to GDll2mm_cea ******************************************************************************/ @@ -109,7 +109,7 @@ static char GDXSDdims[HDFE_DIMBUFSIZE]; #define NGRID 200 /* Grid Structure External Arrays */ -struct gridStructure +struct gridStructure { int32 active; int32 IDTable; @@ -147,10 +147,10 @@ struct gridRegion static struct gridRegion *GDXRegion[NGRIDREGN]; /* define a macro for the string size of the utility strings and some dimension - list strings. The value of 80 in the previous version of this code - may not be enough in some cases. The length now is 512 which seems to + list strings. The value of 80 in the previous version of this code + may not be enough in some cases. The length now is 512 which seems to be more than enough to hold larger strings. */ - + #define UTLSTR_MAX_SIZE 512 /* Static projection table */ @@ -221,7 +221,7 @@ static const char * const pixregNames[] = { /* Grid Function Prototypes (internal routines) */ static intn GDchkgdid(int32, const char *, int32 *, int32 *, int32 *); -static intn GDSDfldsrch(int32, int32, const char *, int32 *, int32 *, +static intn GDSDfldsrch(int32, int32, const char *, int32 *, int32 *, int32 *, int32 *, int32 [], int32 *); static intn GDwrrdfield(int32, const char *, const char *, int32 [], int32 [], int32 [], VOIDP datbuf); @@ -471,7 +471,7 @@ GDcreate(int32 fid, const char *gridname, int32 xdimsize, int32 ydimsize, "\t\tYDim=", (int)ydimsize, "\n"); - snprintf(footer, sizeof(footer), + snprintf(footer, sizeof(footer), "%s%s%s%s%s%s%s%d%s", "\t\tGROUP=Dimension\n", "\t\tEND_GROUP=Dimension\n", @@ -673,13 +673,13 @@ GDattach(int32 fid, const char *gridname) /* ----------------------------------------------------- */ tags = (int32 *) malloc(sizeof(int32) * 2); if(tags == NULL) - { + { HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * 2); if(refs == NULL) - { + { HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__); free(tags); return(-1); @@ -730,13 +730,13 @@ GDattach(int32 fid, const char *gridname) /* ----------------------------------------- */ tags = (int32 *) malloc(sizeof(int32) * nObjects); if(tags == NULL) - { + { HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * nObjects); if(refs == NULL) - { + { HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__); free(tags); return(-1); @@ -755,7 +755,7 @@ GDattach(int32 fid, const char *gridname) } GDXGrid[i].sdsID = (int32 *) calloc(nSDS, 4); if(GDXGrid[i].sdsID == NULL && nSDS != 0) - { + { HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__); free(tags); free(refs); @@ -882,7 +882,10 @@ GDchkgdid(int32 gridID, const char *routname, /* Compute "reduced" ID */ /* -------------------- */ gID = gridID % idOffset; - + if (gID >= NGRID) + { + return -1; + } /* Check for active grid ID */ /* ------------------------ */ @@ -971,11 +974,17 @@ GDdefdim(int32 gridID, const char *dimname, int32 dim) /* -------------------------------------- */ if (status == 0) { - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); /* The cast to char* is somehow nasty since EHinsertmeta can modify */ /* dimname, but not in this case since we call with metacode = 0 */ + int32 dimArray[1] = { dim }; status = EHinsertmeta(sdInterfaceID, gridname, "g", 0L, - (char*) dimname, &dim); + (char*) dimname, dimArray); } return (status); @@ -1052,26 +1061,27 @@ GDdefproj(int32 gridID, int32 projcode, int32 zonecode, int32 spherecode, for (i = 0; i < 13; i++) { + char utlbufSmall[32]; /* If projparm[i] = 0 ... */ if (projparm[i] == 0.0) { - strcpy(utlbuf, "0,"); + strcpy(utlbufSmall, "0,"); } else { /* if projparm[i] is integer ... */ if ((int32) projparm[i] == projparm[i]) { - snprintf(utlbuf, sizeof(utlbuf), "%d%s", + snprintf(utlbufSmall, sizeof(utlbufSmall), "%d%s", (int) projparm[i], ","); } /* else projparm[i] is non-zero floating point ... */ else { - CPLsnprintf(utlbuf, sizeof(utlbuf), "%f%s", projparm[i], ","); + CPLsnprintf(utlbufSmall, sizeof(utlbufSmall), "%f%s", projparm[i], ","); } } - strcat(projparmbuf, utlbuf); + strcat(projparmbuf, utlbufSmall); } slen = (int)strlen(projparmbuf); @@ -1116,7 +1126,12 @@ GDdefproj(int32 gridID, int32 projcode, int32 zonecode, int32 spherecode, /* Insert in structural metadata */ /* ----------------------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); status = EHinsertmeta(sdInterfaceID, gridname, "g", 101L, utlbuf, NULL); } @@ -1186,7 +1201,12 @@ GDblkSOMoffset(int32 gridID, float32 offset[], int32 count, const char *code) /* If SOM projection with projparm[11] non-zero ... */ if (projcode == GCTP_SOM && projparm[11] != 0) { - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); snprintf(utlbuf, sizeof(utlbuf),"%s%s", "_BLKSOM:", gridname); /* Write offset values as attribute */ @@ -1252,7 +1272,10 @@ GDdefcomp(int32 gridID, int32 compcode, intn compparm[]) if (status == 0) { gID = gridID % idOffset; - + if (gID >= NGRID) + { + return -1; + } /* Set compression code in compression external array */ GDXGrid[gID].compcode = compcode; @@ -1334,6 +1357,8 @@ GDdeftile(int32 gridID, int32 tilecode, int32 tilerank, int32 tiledims[]) if (status == 0) { gID = gridID % idOffset; + if (gID >= NGRID) + return -1; for (i = 0; i < 8; i++) { @@ -1431,12 +1456,17 @@ GDdeforigin(int32 gridID, int32 origincode) { /* If proper origin code then write to structural metadata */ /* ------------------------------------------------------- */ - if (origincode >= 0 && origincode < (int32)sizeof(originNames)) + if (origincode >= 0 && origincode < (int32)(sizeof(originNames) / sizeof(originNames[0]))) { + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } snprintf(utlbuf, sizeof(utlbuf),"%s%s%s", "\t\tGridOrigin=", originNames[origincode], "\n"); - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + Vgetname(GDXGrid[gID].IDTable, gridname); status = EHinsertmeta(sdInterfaceID, gridname, "g", 101L, utlbuf, NULL); } @@ -1503,12 +1533,17 @@ GDdefpixreg(int32 gridID, int32 pixregcode) { /* If proper pix reg code then write to structural metadata */ /* -------------------------------------------------------- */ - if (pixregcode >= 0 && pixregcode < (int32)sizeof(pixregNames)) + if (pixregcode >= 0 && pixregcode < (int32)(sizeof(pixregNames) / sizeof(pixregNames[0]))) { + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } snprintf(utlbuf, sizeof(utlbuf),"%s%s%s", "\t\tPixelRegistration=", pixregNames[pixregcode], "\n"); - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + Vgetname(GDXGrid[gID].IDTable, gridname); status = EHinsertmeta(sdInterfaceID, gridname, "g", 101L, utlbuf, NULL); } @@ -1581,7 +1616,7 @@ GDdiminfo(int32 gridID, const char *dimname) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDdiminfo", __FILE__, __LINE__); return(-1); } @@ -1599,7 +1634,13 @@ GDdiminfo(int32 gridID, const char *dimname) { /* Get grid name */ /* ------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to "Dimension" section within SM */ @@ -1611,7 +1652,7 @@ GDdiminfo(int32 gridID, const char *dimname) { free(utlstr); return(-1); - } + } /* Search for dimension name (surrounded by quotes) */ /* ------------------------------------------------ */ @@ -1711,7 +1752,7 @@ GDgridinfo(int32 gridID, int32 * xdimsize, int32 * ydimsize, /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDgridinfo", __FILE__, __LINE__); return(-1); } @@ -1723,7 +1764,13 @@ GDgridinfo(int32 gridID, int32 * xdimsize, int32 * ydimsize, { /* Get grid name */ /* ------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to grid structure section within SM */ @@ -1735,7 +1782,7 @@ GDgridinfo(int32 gridID, int32 * xdimsize, int32 * ydimsize, { free(utlstr); return(-1); - } + } /* Get xdimsize if requested */ @@ -1904,7 +1951,7 @@ GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode, /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDprojinfo", __FILE__, __LINE__); return(-1); } @@ -1917,7 +1964,14 @@ GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode, { /* Get grid name */ /* ------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to grid structure section within SM */ @@ -1929,7 +1983,7 @@ GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode, { free(utlstr); return(-1); - } + } /* Get projcode if requested */ @@ -1969,7 +2023,7 @@ GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode, /* Get zonecode if requested */ /* ------------------------- */ - if (zonecode != NULL) + if (projcode && zonecode != NULL) { *zonecode = -1; @@ -1996,7 +2050,7 @@ GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode, /* Get projection parameters if requested */ /* -------------------------------------- */ - if (projparm != NULL) + if (projcode && projparm != NULL) { /* @@ -2052,7 +2106,7 @@ GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode, /* Get spherecode if requested */ /* --------------------------- */ - if (spherecode != NULL) + if (projcode && spherecode != NULL) { *spherecode = 0; @@ -2127,7 +2181,7 @@ GDorigininfo(int32 gridID, int32 * origincode) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDorigininfo", __FILE__, __LINE__); return(-1); } @@ -2150,7 +2204,14 @@ GDorigininfo(int32 gridID, int32 * origincode) /* Get grid name */ /* ------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to grid structure section within SM */ @@ -2162,7 +2223,7 @@ GDorigininfo(int32 gridID, int32 * origincode) { free(utlstr); return(-1); - } + } statmeta = EHgetmetavalue(metaptrs, "GridOrigin", utlstr); @@ -2173,7 +2234,7 @@ GDorigininfo(int32 gridID, int32 * origincode) * If "GridOrigin" string found in metadata then convert to * numeric origin code (fixed added: Jan 97) */ - for (i = 0; i < (intn)sizeof(originNames); i++) + for (i = 0; i < (intn)(sizeof(originNames) / sizeof(originNames[0])); i++) { if (strcmp(utlstr, originNames[i]) == 0) { @@ -2249,7 +2310,7 @@ GDpixreginfo(int32 gridID, int32 * pixregcode) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDpixreginfo", __FILE__, __LINE__); return(-1); } @@ -2266,7 +2327,14 @@ GDpixreginfo(int32 gridID, int32 * pixregcode) *pixregcode = 0; /* Get grid name */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to grid structure section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g", @@ -2276,7 +2344,7 @@ GDpixreginfo(int32 gridID, int32 * pixregcode) { free(utlstr); return(-1); - } + } statmeta = EHgetmetavalue(metaptrs, "PixelRegistration", utlstr); @@ -2288,7 +2356,7 @@ GDpixreginfo(int32 gridID, int32 * pixregcode) * to numeric origin code (fixed added: Jan 97) */ - for (i = 0; i < (intn)sizeof(pixregNames); i++) + for (i = 0; i < (intn)(sizeof(pixregNames) / sizeof(pixregNames[0])); i++) { if (strcmp(utlstr, pixregNames[i]) == 0) { @@ -2358,7 +2426,7 @@ GDcompinfo(int32 gridID, const char *fieldname, int32 * compcode, intn compparm[ /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDcompinfo", __FILE__, __LINE__); return(-1); } @@ -2369,7 +2437,13 @@ GDcompinfo(int32 gridID, const char *fieldname, int32 * compcode, intn compparm[ if (status == 0) { /* Get grid name */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to "DataField" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g", @@ -2378,7 +2452,7 @@ GDcompinfo(int32 gridID, const char *fieldname, int32 * compcode, intn compparm[ { free(utlstr); return(-1); - } + } /* Search for field */ @@ -2407,7 +2481,7 @@ GDcompinfo(int32 gridID, const char *fieldname, int32 * compcode, intn compparm[ if (statmeta == 0) { /* Loop through compression types until match */ - for (i = 0; i < (intn)sizeof(HDFcomp); i++) + for (i = 0; i < (intn)(sizeof(HDFcomp) / sizeof(HDFcomp[0])); i++) { if (strcmp(utlstr, HDFcomp[i]) == 0) { @@ -2556,7 +2630,7 @@ GDfieldinfo(int32 gridID, const char *fieldname, int32 * rank, int32 dims[], /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDfieldinfo", __FILE__, __LINE__); return(-1); } @@ -2567,8 +2641,13 @@ GDfieldinfo(int32 gridID, const char *fieldname, int32 * rank, int32 dims[], if (status == 0) { - - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g", "DataField", metaptrs); @@ -2576,7 +2655,7 @@ GDfieldinfo(int32 gridID, const char *fieldname, int32 * rank, int32 dims[], { free(utlstr); return(-1); - } + } /* Search for field */ @@ -2819,6 +2898,10 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, { /* Remove offset from grid ID & get gridname */ gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } Vgetname(GDXGrid[gID].IDTable, gridname); @@ -2826,13 +2909,13 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, /* ---------------------------------------------------------------- */ dimbuf = (char *) calloc(strlen(dimlist) + 64, 1); if(dimbuf == NULL) - { + { HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__); return(-1); } dimlist0 = (char *) calloc(strlen(dimlist) + 64, 1); if(dimlist0 == NULL) - { + { HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__); free(dimbuf); return(-1); @@ -2897,7 +2980,7 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, /* ------------------------------------- */ dimcheck = (char *) calloc(comma - dimbuf + 1, 1); if(dimcheck == NULL) - { + { HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__); free(dimbuf); free(dimlist0); @@ -2954,12 +3037,13 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, foundAllDim = 0; if (first == 1) { - strcpy(utlbuf, dimcheck); + snprintf(utlbuf, sizeof(utlbuf), "%s", dimcheck); } else { - strcat(utlbuf, ","); - strcat(utlbuf, dimcheck); + char utlbufTmp[sizeof(utlbuf)]; + strcpy(utlbufTmp, utlbuf); + CPLsnprintf(utlbuf, sizeof(utlbuf), "%s,%s", utlbufTmp, dimcheck); } first = 0; } @@ -2981,7 +3065,7 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, { /* if ((intn) strlen(fieldname) > MAX_NC_NAME - 7) ** this was changed because HDF4.1r3 made a change in the -** hlimits.h file. We have notified NCSA and asked to have +** hlimits.h file. We have notified NCSA and asked to have ** it made the same as in previous versions of HDF ** see ncr 26314. DaW Apr 2000 */ @@ -3299,7 +3383,7 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, realloc((void *) GDXGrid[gID].sdsID, (GDXGrid[gID].nSDS + 1) * 4); if(GDXGrid[gID].sdsID == NULL) - { + { HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__); free(dimlist0); return(-1); @@ -3311,7 +3395,7 @@ GDdeffield(int32 gridID, const char *fieldname, const char *dimlist, /* -------------------- */ GDXGrid[gID].sdsID = (int32 *) calloc(1, 4); if(GDXGrid[gID].sdsID == NULL) - { + { HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__); free(dimlist0); return(-1); @@ -3474,9 +3558,16 @@ GDwritefieldmeta(int32 gridID, const char *fieldname, const char *dimlist, { snprintf(utlbuf, sizeof(utlbuf), "%s%s%s", fieldname, ":", dimlist); - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + + Vgetname(GDXGrid[gID].IDTable, gridname); + int32 numbertypeArray[1] = { numbertype }; status = EHinsertmeta(sdInterfaceID, gridname, "g", 4L, - utlbuf, &numbertype); + utlbuf, numbertypeArray); } return (status); } @@ -3548,7 +3639,7 @@ GDSDfldsrch(int32 gridID, int32 sdInterfaceID, const char *fieldname, /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDSDfldsrch", __FILE__, __LINE__); return(-1); } @@ -3560,7 +3651,11 @@ GDSDfldsrch(int32 gridID, int32 sdInterfaceID, const char *fieldname, /* Compute "reduced" grid ID */ /* ------------------------- */ gID = gridID % idOffset; - + if (gID >= NGRID) + { + free(utlstr); + return -1; + } /* Loop through all SDSs in grid */ /* ----------------------------- */ @@ -3594,7 +3689,7 @@ GDSDfldsrch(int32 gridID, int32 sdInterfaceID, const char *fieldname, { free(utlstr); return(-1); - } + } #ifdef broken_logic /* Initialize metaptr to beg. of section */ @@ -4133,7 +4228,12 @@ GDwrrdattr(int32 gridID, const char *attrname, int32 numbertype, int32 count, { /* Perform Attribute I/O */ /* --------------------- */ - attrVgrpID = GDXGrid[gridID % idOffset].VIDTable[1]; + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + attrVgrpID = GDXGrid[gID].VIDTable[1]; status = EHattr(fid, attrVgrpID, attrname, numbertype, count, wrcode, datbuf); } @@ -4279,7 +4379,12 @@ GDattrinfo(int32 gridID, const char *attrname, int32 * numbertype, int32 * count status = GDchkgdid(gridID, "GDattrinfo", &fid, &dum, &dum); - attrVgrpID = GDXGrid[gridID % idOffset].VIDTable[1]; + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + attrVgrpID = GDXGrid[gID].VIDTable[1]; status = EHattrinfo(fid, attrVgrpID, attrname, numbertype, count); @@ -4343,7 +4448,12 @@ GDinqattrs(int32 gridID, char *attrnames, int32 * strbufsize) if (status == 0) { - attrVgrpID = GDXGrid[gridID % idOffset].VIDTable[1]; + int gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } + attrVgrpID = GDXGrid[gID].VIDTable[1]; nattr = EHattrcat(fid, attrVgrpID, attrnames, strbufsize); } @@ -4420,7 +4530,7 @@ GDinqdims(int32 gridID, char *dimnames, int32 dims[]) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDinqdims", __FILE__, __LINE__); return(-1); } @@ -4436,7 +4546,13 @@ GDinqdims(int32 gridID, char *dimnames, int32 dims[]) { /* Get grid name */ /* ------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to "Dimension" section within SM */ @@ -4447,8 +4563,8 @@ GDinqdims(int32 gridID, char *dimnames, int32 dims[]) { free(utlstr); return(-1); - } - + } + /* If dimension names are requested then "clear" name buffer */ /* --------------------------------------------------------- */ @@ -4576,7 +4692,7 @@ GDinqfields(int32 gridID, char *fieldlist, int32 rank[], /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDinqfields", __FILE__, __LINE__); return(-1); } @@ -4592,7 +4708,13 @@ GDinqfields(int32 gridID, char *fieldlist, int32 rank[], { /* Get grid name */ /* ------------- */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + Vgetname(GDXGrid[gID].IDTable, gridname); /* Get pointers to "DataField" section within SM */ @@ -4603,7 +4725,7 @@ GDinqfields(int32 gridID, char *fieldlist, int32 rank[], { free(utlstr); return(-1); - } + } /* If field names are desired then "clear" name buffer */ @@ -4757,16 +4879,18 @@ GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize) int32 nVal = 0; /* Number of strings to search for */ char *metabuf = NULL; /* Pointer to structural metadata (SM) */ - char *metaptrs[2];/* Pointers to begin and end of SM section */ + char *metaptrs[2] = {NULL, NULL};/* Pointers to begin and end of SM section */ char gridname[80]; /* Grid Name */ char *utlstr;/* Utility string */ char valName[2][32]; /* Strings to search for */ + memset(valName, 0, sizeof(valName)); + /* Allocate space for utility string */ /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"GDnentries", __FILE__, __LINE__); return(-1); } @@ -4775,7 +4899,14 @@ GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize) if (status == 0) { /* Get grid name */ - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlstr); + return -1; + } + + Vgetname(GDXGrid[gID].IDTable, gridname); /* Zero out string buffer size */ *strbufsize = 0; @@ -4795,8 +4926,8 @@ GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize) { free(utlstr); return(-1); - } - + } + nVal = 1; strcpy(&valName[0][0], "DimensionName"); } @@ -4810,7 +4941,7 @@ GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize) { free(utlstr); return(-1); - } + } nVal = 1; strcpy(&valName[0][0], "DataFieldName"); @@ -4818,6 +4949,11 @@ GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize) break; } + if (!metabuf || metaptrs[0] == NULL) + { + free(metabuf); + return -1; + } /* * Check for presence of 'GROUP="' string If found then old metadata, @@ -5181,6 +5317,10 @@ GDdetach(int32 gridID) if (status == 0) { gID = gridID % idOffset; + if (gID >= NGRID) + { + return -1; + } Vgetname(GDXGrid[gID].IDTable, gridname); /* SDS combined fields */ @@ -5193,20 +5333,20 @@ GDdetach(int32 gridID) /* ---------------------------------------------------- */ nameptr = (char **) calloc(1, sizeof(char *)); if(nameptr == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); return(-1); } namelen = (int32 *) calloc(1, sizeof(int32)); if(namelen == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); return(-1); } nameptr0 = (char **) calloc(1, sizeof(char *)); if(nameptr0 == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5214,7 +5354,7 @@ GDdetach(int32 gridID) } namelen0 = (int32 *) calloc(1, sizeof(int32)); if(namelen0 == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5223,7 +5363,7 @@ GDdetach(int32 gridID) } dimptr = (char **) calloc(1, sizeof(char *)); if(dimptr == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5233,7 +5373,7 @@ GDdetach(int32 gridID) } dimlen = (int32 *) calloc(1, sizeof(int32)); if(dimlen == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5244,7 +5384,7 @@ GDdetach(int32 gridID) } offset = (int32 *) calloc(1, sizeof(int32)); if(offset == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5256,7 +5396,7 @@ GDdetach(int32 gridID) } indvdims = (int32 *) calloc(1, sizeof(int32)); if(indvdims == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5286,20 +5426,20 @@ GDdetach(int32 gridID) /* ----------------------------------------- */ nameptr = (char **) calloc(nflds, sizeof(char *)); if(nameptr == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); return(-1); } namelen = (int32 *) calloc(nflds, sizeof(int32)); if(namelen == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); return(-1); } nameptr0 = (char **) calloc(nflds, sizeof(char *)); if(nameptr0 == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5307,7 +5447,7 @@ GDdetach(int32 gridID) } namelen0 = (int32 *) calloc(nflds, sizeof(int32)); if(namelen0 == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5316,7 +5456,7 @@ GDdetach(int32 gridID) } dimptr = (char **) calloc(nflds, sizeof(char *)); if(dimptr == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5326,7 +5466,7 @@ GDdetach(int32 gridID) } dimlen = (int32 *) calloc(nflds, sizeof(int32)); if(dimlen == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5337,7 +5477,7 @@ GDdetach(int32 gridID) } offset = (int32 *) calloc(nflds, sizeof(int32)); if(offset == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5349,7 +5489,7 @@ GDdetach(int32 gridID) } indvdims = (int32 *) calloc(nflds, sizeof(int32)); if(indvdims == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5375,7 +5515,7 @@ GDdetach(int32 gridID) { nambuf = (char *) calloc(strlen(GDXSDname) + 1, 1); if(nambuf == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -5384,11 +5524,12 @@ GDdetach(int32 gridID) free(dimptr); free(dimlen); free(offset); + free(indvdims); return(-1); } utlbuf = (char *) calloc(strlen(GDXSDname) * 2 + 7, 1); if(utlbuf == NULL) - { + { HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__); free(nambuf); free(nameptr); @@ -5398,6 +5539,7 @@ GDdetach(int32 gridID) free(dimptr); free(dimlen); free(offset); + free(indvdims); return(-1); } @@ -5783,7 +5925,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], float64 lon, lat, plat, x, y; float64 plon, tlon, llon, rlon, pplon, LLon, LLat, RLon, RLat; - + /* invoke GCTP initialization routine */ /* ---------------------------------- */ @@ -5823,7 +5965,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], LLat = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LAT, HDFE_DEG_RAD); RLon = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LON, HDFE_DEG_RAD); RLat = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LAT, HDFE_DEG_RAD); - + errorcode = for_trans[projcode] (LLon, LLat, &x, &y); if (errorcode != 0) { @@ -5834,7 +5976,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } upleftpt[0] = x; upleftpt[1] = y; - + errorcode = for_trans[projcode] (RLon, RLat, &x, &y); if (errorcode != 0) { @@ -5845,10 +5987,10 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } lowrightpt[0] = x; lowrightpt[1] = y; - + } - - + + /* Compute Default Boundary Points for Polar Sterographic */ /* ------------------------------------------------------ */ if (projcode == GCTP_PS && @@ -5907,7 +6049,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } upleftpt[0] = x; - + errorcode = for_trans[projcode] (rlon, 0.0, &x, &y); if (errorcode != 0) { @@ -5918,7 +6060,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } lowrightpt[0] = x; - + /* * Compute the upperleft and lowright y values based on the south or * north polar projection @@ -5936,7 +6078,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } upleftpt[1] = y; - + errorcode = for_trans[projcode] (tlon, 0.0, &x, &y); if (errorcode != 0) { @@ -5947,7 +6089,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } lowrightpt[1] = y; - + } else { @@ -5961,7 +6103,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } upleftpt[1] = y; - + errorcode = for_trans[projcode] (plon, 0.0, &x, &y); if (errorcode != 0) { @@ -5972,7 +6114,7 @@ GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[], } lowrightpt[1] = y; - + } } @@ -6394,8 +6536,8 @@ GDll2ij(int32 projcode, int32 zonecode, float64 projparm[], of r_major and r_minor) using GCTP */ /* ----------------------------------------- */ errorcode = for_trans[projcode] (lonrad0, latrad0, &xMtr0, &yMtr0); - - + + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -6410,8 +6552,8 @@ GDll2ij(int32 projcode, int32 zonecode, float64 projparm[], of r_major and r_minor) using GCTP */ /* ----------------------------------------- */ errorcode = for_trans[projcode] (lonrad, latrad, &xMtr1, &yMtr1); - - + + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -6478,7 +6620,7 @@ GDll2ij(int32 projcode, int32 zonecode, float64 projparm[], /* ----------------------------------------- */ errorcode = for_trans[projcode] (lonrad, latrad, &xMtr, &yMtr); - + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -6494,13 +6636,13 @@ GDll2ij(int32 projcode, int32 zonecode, float64 projparm[], else { /* if projection is BCEA normalize x and y by cell size and measure it from the upperleft corner of the grid */ - + /* Compute scaled distance to point from origin */ /* -------------------------------------------- */ if( projcode == GCTP_BCEA) { xVal = (xMtr - xMtr0) / scaleX; - yVal = (yMtr - yMtr0) / scaleY; + yVal = (yMtr - yMtr0) / scaleY; } else { @@ -6602,9 +6744,9 @@ GDrs2ll(int32 projcode, float64 projparm[], float64 eccen, eccen_sq; float64 phi1, sinphi1, cosphi1; float64 scaleX, scaleY; - + int32 zonecode=0; - + int32 spherecode=0; float64 lon[2],lat[2]; float64 xcor[2], ycor[2]; @@ -6621,7 +6763,7 @@ GDrs2ll(int32 projcode, float64 projparm[], } else { - qp_cea = + qp_cea = (1.0 - eccen_sq)*((1.0/(1.0 - eccen_sq))-(1.0/(2.0*eccen))* log((1.0 - eccen)/(1.0 + eccen))); } @@ -6630,7 +6772,7 @@ GDrs2ll(int32 projcode, float64 projparm[], sinphi1 = sin(phi1); kz_cea = cosphi1/(sqrt(1.0 - (eccen_sq*sinphi1*sinphi1))); } - + @@ -6690,10 +6832,10 @@ GDrs2ll(int32 projcode, float64 projparm[], /* ------------------------------------------------------ */ if (projcode == GCTP_BCEA) { - + inv_init(projcode, 0, projparm, 0, NULL, NULL, &errorcode, inv_trans); - + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -6708,7 +6850,7 @@ GDrs2ll(int32 projcode, float64 projparm[], /* ------------------ */ for (i = 0; i < npnts; i++) { - /* Convert from EASE grid's (r,s) to lon/lat (radians) + /* Convert from EASE grid's (r,s) to lon/lat (radians) using GCTP */ /* --------------------------------------------------- */ nlatlon = 2; @@ -6716,32 +6858,32 @@ GDrs2ll(int32 projcode, float64 projparm[], lon[1] = lowright[0]; lat[0] = upleft[1]; lat[1] = lowright[1]; - status = + status = GDll2mm_cea(projcode,zonecode,spherecode,projparm, xdimsize, ydimsize, upleft, lowright, nlatlon, lon, lat, xcor, ycor, &scaleX, &scaleY); - + if (status == -1) { HEpush(DFE_GENAPP, "GDrs2ll", __FILE__, __LINE__); return (status); } - + xMtr = (r[i]/ scaleX + pixadjX - 0.5)* scaleX; yMtr = - (s[i]/fabs(scaleY) + pixadjY - 0.5)* fabs(scaleY); - - /* allow .5 cell tolerance in arcsin function + + /* allow .5 cell tolerance in arcsin function (used in bceainv function) so that grid coordinates which are less than .5 cells - above 90.00N or below 90.00S are given lat of 90.00 + above 90.00N or below 90.00S are given lat of 90.00 */ epsilon = 1 + 0.5 * (fabs(scaleY)/projparm[0]); beta = 2.0 * (yMtr - projparm[7]) * kz_cea/(projparm[0] * qp_cea); - + if( fabs (beta) > epsilon) { status = -1; @@ -6768,7 +6910,7 @@ GDrs2ll(int32 projcode, float64 projparm[], errorcode = inv_trans[projcode] (xMtr, yMtr, &lonrad, &latrad); } - + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -6778,7 +6920,7 @@ GDrs2ll(int32 projcode, float64 projparm[], HEreport("GCTP Error: %d\n", errorcode); return (status); } - + /* Convert from radians to decimal degrees */ /* --------------------------------------- */ longitude[i] = EHconvAng(lonrad, HDFE_RAD_DEG); @@ -6789,7 +6931,7 @@ GDrs2ll(int32 projcode, float64 projparm[], - + return (status); } @@ -7063,13 +7205,13 @@ GDtangentpnts(int32 projcode, float64 projparm[], float64 cornerlon[], { case GCTP_MERCAT: { - /* No need for tangent points, since MERCAT projection + /* No need for tangent points, since MERCAT projection is rectangular */ } break; case GCTP_BCEA: { - /* No need for tangent points, since BCEA projection + /* No need for tangent points, since BCEA projection is rectangular */ } break; @@ -7664,13 +7806,13 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) utlbuf = (char *)calloc(128, sizeof(char)); if(utlbuf == NULL) - { + { HEpush(DFE_NOSPACE,"GDdefboxregion", __FILE__, __LINE__); return(-1); } gridname = (char *)calloc(128, sizeof(char)); if(gridname == NULL) - { + { HEpush(DFE_NOSPACE,"GDdefboxregion", __FILE__, __LINE__); free(utlbuf); return(-1); @@ -7688,8 +7830,8 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) /* ------------- */ status = GDgridinfo(gridID, &xdimsize, &ydimsize, upleftpt, lowrightpt); - - + + /* If error then bail */ /* ------------------ */ if (status != 0) @@ -7760,11 +7902,19 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) /* ------------------------------------------------- */ status = GDtangentpnts(projcode, projparm, cornerlon, cornerlat, longitude, latitude, &npnts); - + /* If SOM projection with projparm[11] non-zero ... */ if (projcode == GCTP_SOM && projparm[11] != 0) { - Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname); + int gID = gridID % idOffset; + if (gID >= NGRID) + { + free(utlbuf); + free(gridname); + return -1; + } + + Vgetname(GDXGrid[gID].IDTable, gridname); snprintf(utlbuf, 128, "%s%s", "_BLKSOM:", gridname); status = GDreadattr(gridID, utlbuf, offset); @@ -7828,7 +7978,7 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) /* Check whether subset region is outside grid region */ /* -------------------------------------------------- */ - if (minCol >= xdimsize || minRow >= ydimsize || + if (minCol >= xdimsize || minRow >= ydimsize || maxCol < 0 || maxRow < 0) { if ( blockindexstart == -1 && (projparm[11]) == j) @@ -7944,7 +8094,7 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) GDXRegion[i] = (struct gridRegion *) calloc(1, sizeof(struct gridRegion)); if(GDXRegion[i] == NULL) - { + { HEpush(DFE_NOSPACE,"GDdefboxregion", __FILE__, __LINE__); free(utlbuf); free(gridname); @@ -8037,7 +8187,7 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) lon[1] = lowrightpt[0]; lat[0] = upleftpt[1]; lat[1] = lowrightpt[1]; - status = + status = GDll2mm_cea(projcode,zonecode,spherecode,projparm, xdimsize, ydimsize, upleftpt, lowrightpt,nlatlon, @@ -8045,8 +8195,8 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) xcor, ycor, &xscale, &yscale); upleftpt_m[0] = xcor[0]; upleftpt_m[1] = ycor[0]; - - + + if (status == -1) { HEpush(DFE_GENAPP, "GDdefboxregion", __FILE__, __LINE__); @@ -8077,7 +8227,7 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) status = GDmm2ll_cea(projcode, zonecode, spherecode, projparm, xdimsize, ydimsize, upleftpt, lowrightpt, npnts, - xmtr, ymtr, + xmtr, ymtr, longitude, latitude); if (status == -1) { @@ -8117,17 +8267,17 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) } else { - GDXRegion[i]->upleftpt[0] = + GDXRegion[i]->upleftpt[0] = (lowrightpt[0] - upleftpt[0])* (offset[blockindexstart-1]/xdimsize) + upleftpt[0]; - GDXRegion[i]->upleftpt[1] = + GDXRegion[i]->upleftpt[1] = (lowrightpt[1] - upleftpt[1])* (blockindexstart+1-1) + upleftpt[1]; - GDXRegion[i]->lowrightpt[0] = + GDXRegion[i]->lowrightpt[0] = (lowrightpt[0] - upleftpt[0])* (offset[blockindexstart-1]/xdimsize) + lowrightpt[0]; - GDXRegion[i]->lowrightpt[1] = + GDXRegion[i]->lowrightpt[1] = (lowrightpt[1] - upleftpt[1])* (blockindexstart+1-1) + lowrightpt[1]; @@ -8173,10 +8323,10 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) regionID = i; break; } - + } } - + } free(utlbuf); free(gridname); @@ -8771,7 +8921,7 @@ GDdupregion(int32 oldregionID) GDXRegion[i] = (struct gridRegion *) calloc(1, sizeof(struct gridRegion)); if(GDXRegion[i] == NULL) - { + { HEpush(DFE_NOSPACE,"GDdupregion", __FILE__, __LINE__); return(-1); } @@ -8779,7 +8929,7 @@ GDdupregion(int32 oldregionID) /* Copy old region structure data to new region */ /* -------------------------------------------- */ - + GDXRegion[i]->fid = GDXRegion[oldregionID]->fid; GDXRegion[i]->gridID = GDXRegion[oldregionID]->gridID; GDXRegion[i]->xStart = GDXRegion[oldregionID]->xStart; @@ -8795,7 +8945,7 @@ GDdupregion(int32 oldregionID) GDXRegion[i]->StartVertical[j] = GDXRegion[oldregionID]->StartVertical[j]; GDXRegion[i]->StopVertical[j] = GDXRegion[oldregionID]->StopVertical[j]; } - + for (j=0; j<8; j++) { if(GDXRegion[oldregionID]->DimNamePtr[j] != NULL) @@ -8805,7 +8955,7 @@ GDdupregion(int32 oldregionID) strcpy(GDXRegion[i]->DimNamePtr[j],GDXRegion[oldregionID]->DimNamePtr[j]); } } - + /* Define new region ID */ /* -------------------- */ @@ -8853,6 +9003,7 @@ GDdupregion(int32 oldregionID) -----------------------------------------------------------------------------*/ #define SETGRIDREG \ \ +regionID = 0; \ status = GDgridinfo(gridID, &xdimsize, &ydimsize, upleftpt, lowrightpt); \ for (k = 0; k < NGRIDREGN; k++) \ { \ @@ -8922,7 +9073,7 @@ GDdefvrtregion(int32 gridID, int32 regionID, const char *vertObj, float64 range[ /* --------------------------------- */ dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(dimlist == NULL) - { + { HEpush(DFE_NOSPACE,"GDdefvrtregion", __FILE__, __LINE__); return(-1); } @@ -8952,7 +9103,7 @@ GDdefvrtregion(int32 gridID, int32 regionID, const char *vertObj, float64 range[ GDXRegion[regionID]->DimNamePtr[j] = (char *) malloc(slen + 1); if(GDXRegion[regionID]->DimNamePtr[j] == NULL) - { + { HEpush(DFE_NOSPACE,"GDdefvrtregion", __FILE__, __LINE__); free(dimlist); return(-1); @@ -8987,7 +9138,7 @@ GDdefvrtregion(int32 gridID, int32 regionID, const char *vertObj, float64 range[ size = DFKNTsize(nt); vertArr = (char *) calloc(dims[0], size); if(vertArr == NULL) - { + { HEpush(DFE_NOSPACE,"GDdefvrtregion", __FILE__, __LINE__); free(dimlist); return(-1); @@ -9320,13 +9471,13 @@ GDgetpixels(int32 gridID, int32 nLonLat, float64 lonVal[], float64 latVal[], /* ---------------------------------- */ xVal = (float64 *) calloc(nLonLat, sizeof(float64)); if(xVal == NULL) - { + { HEpush(DFE_NOSPACE,"GDgetpixels", __FILE__, __LINE__); return(-1); } yVal = (float64 *) calloc(nLonLat, sizeof(float64)); if(yVal == NULL) - { + { HEpush(DFE_NOSPACE,"GDgetpixels", __FILE__, __LINE__); free(xVal); return(-1); @@ -9496,7 +9647,7 @@ GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[], /* --------------------------------- */ dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(dimlist == NULL) - { + { HEpush(DFE_NOSPACE,"GDgetpixvalues", __FILE__, __LINE__); return(-1); } @@ -9619,9 +9770,9 @@ GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[], /* Set I/O offset and count Section */ /* ---------------------- */ - + /* - * start and edge != NULL, set I/O offset and count to + * start and edge != NULL, set I/O offset and count to * user values, adjusting the * 0th field with the merged field offset (if any) */ @@ -9649,12 +9800,12 @@ GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[], offset[0] = mrgOffset; count[0] = 1; } - - - + + + /* Set I/O stride Section */ /* ---------------------- */ - + /* In original code stride entered as NULL. Abe Taaheri June 12, 1998 */ /* @@ -9664,7 +9815,7 @@ GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[], { incr[j] = 1; } - + /* Read into data buffer */ /* --------------------- */ @@ -9784,7 +9935,7 @@ GDinterpolate(int32 gridID, int32 nValues, float64 lonVal[], float64 latVal[], /* --------------------------------- */ dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(dimlist == NULL) - { + { HEpush(DFE_NOSPACE,"GDinterpolate", __FILE__, __LINE__); return(-1); } @@ -9963,7 +10114,7 @@ GDinterpolate(int32 gridID, int32 nValues, float64 lonVal[], float64 latVal[], /* -------------------------------- */ pixVal = (char *) malloc(4 * size); if(pixVal == NULL) - { + { HEpush(DFE_NOSPACE,"GDinterpolate", __FILE__, __LINE__); free(dimlist); return(-1); @@ -10501,7 +10652,7 @@ GDsettilecomp(int32 gridID, const char *fieldname, int32 tilerank, int32* tiledims, int32 compcode, intn* compparm) { intn status; /* routine return status variable */ - + int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 gdVgrpID; /* Grid root Vgroup ID */ @@ -10514,18 +10665,18 @@ GDsettilecomp(int32 gridID, const char *fieldname, int32 tilerank, int32* comp_info c_info; /* Compression parameter structure */ HDF_CHUNK_DEF chunkDef; /* Tiling structure */ int32 chunkFlag; /* Chunking (Tiling) flag */ - + c_info.nbit.nt = 0; - + /* Check for valid grid ID and get SDS interface ID */ status = GDchkgdid(gridID, "GDsetfillvalue", &fid, &sdInterfaceID, &gdVgrpID); - + if (status == 0) { /* Get field info */ status = GDfieldinfo(gridID, fieldname, &dum, dims, &nt, NULL); - + if (status == 0) { /* Get SDS ID and solo flag */ @@ -10539,8 +10690,8 @@ GDsettilecomp(int32 gridID, const char *fieldname, int32 tilerank, int32* } /* Tiling with Compression */ /* ----------------------- */ - - + + /* Setup Compression */ /* ----------------- */ if (compcode == HDFE_COMP_NBIT) @@ -10559,19 +10710,19 @@ GDsettilecomp(int32 gridID, const char *fieldname, int32 tilerank, int32* { c_info.deflate.level = compparm[0]; } - + /* Setup chunk lengths */ /* ------------------- */ for (i = 0; i < tilerank; i++) { chunkDef.comp.chunk_lengths[i] = tiledims[i]; } - + /* Setup chunk flag & chunk compression type */ /* ----------------------------------------- */ chunkFlag = HDF_CHUNK | HDF_COMP; chunkDef.comp.comp_type = compcode; - + /* Setup chunk compression parameters */ /* ---------------------------------- */ if (compcode == HDFE_COMP_SKPHUFF) @@ -10673,22 +10824,22 @@ static intn GDll2mm_cea(int32 projcode,int32 zonecode, int32 spherecode, &errorcode, for_trans); /* Convert upleft and lowright X coords from DMS to radians */ /* -------------------------------------------------------- */ - + lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD); lonrad = EHconvAng(lowrightpt[0], HDFE_DMS_RAD); - + /* Convert upleft and lowright Y coords from DMS to radians */ /* -------------------------------------------------------- */ latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD); latrad = EHconvAng(lowrightpt[1], HDFE_DMS_RAD); - + /* Convert from lon/lat to meters(or whatever unit is, i.e unit of r_major and r_minor) using GCTP */ /* ----------------------------------------- */ errorcode = for_trans[projcode] (lonrad0, latrad0, &xMtr0, &yMtr0); x[0] = xMtr0; y[0] = yMtr0; - + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -10698,14 +10849,14 @@ static intn GDll2mm_cea(int32 projcode,int32 zonecode, int32 spherecode, HEreport("GCTP Error: %d\n", errorcode); return (status); } - + /* Convert from lon/lat to meters(or whatever unit is, i.e unit of r_major and r_minor) using GCTP */ /* ----------------------------------------- */ errorcode = for_trans[projcode] (lonrad, latrad, &xMtr1, &yMtr1); x[1] = xMtr1; y[1] = yMtr1; - + /* Report error if any */ /* ------------------- */ if (errorcode != 0) @@ -10715,11 +10866,11 @@ static intn GDll2mm_cea(int32 projcode,int32 zonecode, int32 spherecode, HEreport("GCTP Error: %d\n", errorcode); return (status); } - + /* Compute x scale factor */ /* ---------------------- */ *scaleX = (xMtr1 - xMtr0) / xdimsize; - + /* Compute y scale factor */ /* ---------------------- */ *scaleY = (yMtr1 - yMtr0) / ydimsize; @@ -10777,7 +10928,7 @@ static intn GDmm2ll_cea(int32 projcode,int32 zonecode, int32 spherecode, float64 projparm[], CPL_UNUSED int32 xdimsize, CPL_UNUSED int32 ydimsize, CPL_UNUSED float64 upleftpt[], CPL_UNUSED float64 lowrightpt[], int32 npnts, - float64 x[], float64 y[], + float64 x[], float64 y[], float64 longitude[], float64 latitude[]) { intn status = 0; /* routine return status variable */ @@ -10797,13 +10948,13 @@ static intn GDmm2ll_cea(int32 projcode,int32 zonecode, int32 spherecode, { inv_init(projcode, zonecode, projparm, spherecode, NULL, NULL, &errorcode, inv_trans); - + /* Convert from meters(or whatever unit is, i.e unit of r_major and r_minor) to lat/lon using GCTP */ /* ----------------------------------------- */ for(i=0; i= NSWATH) + { + return -1; + } /* Check for active swath ID */ /* ------------------------- */ - if (SWXSwath[swathID % idOffset].active == 0) + if (SWXSwath[sID].active == 0) { status = -1; HEpush(DFE_GENAPP, "SWchkswid", __FILE__, __LINE__); @@ -856,9 +861,9 @@ SWchkswid(int32 swathID, const char *routname, /* Get file & SDS ids and Swath Vgroup */ /* ----------------------------------- */ - status = EHchkfid(SWXSwath[swathID % idOffset].fid, " ", fid, + status = EHchkfid(SWXSwath[sID].fid, " ", fid, sdInterfaceID, &l_access); - *swVgrpID = SWXSwath[swathID % idOffset].IDTable; + *swVgrpID = SWXSwath[sID].IDTable; } } return (status); @@ -934,9 +939,15 @@ SWdefdim(int32 swathID, char *dimname, int32 dim) /* -------------------------------------- */ if (status == 0) { - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); + int32 dimArray[1] = { dim }; status = EHinsertmeta(sdInterfaceID, swathname, "s", 0L, - dimname, &dim); + dimname, dimArray); } return (status); } @@ -997,7 +1008,7 @@ SWdiminfo(int32 swathID, const char *dimname) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdiminfo", __FILE__, __LINE__); return(-1); } @@ -1010,7 +1021,13 @@ SWdiminfo(int32 swathID, const char *dimname) if (status == 0) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "Dimension" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", @@ -1020,7 +1037,7 @@ SWdiminfo(int32 swathID, const char *dimname) { free(utlstr); return(-1); - } + } /* Search for dimension name (surrounded by quotes) */ snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", dimname, "\"\n"); @@ -1117,7 +1134,7 @@ SWmapinfo(int32 swathID, const char *geodim, const char *datadim, int32 * offset /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWmapinfo", __FILE__, __LINE__); return(-1); } @@ -1131,7 +1148,13 @@ SWmapinfo(int32 swathID, const char *geodim, const char *datadim, int32 * offset if (status == 0) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "DimensionMap" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", @@ -1250,7 +1273,12 @@ SWidxmapinfo(int32 swathID, const char *geodim, const char *datadim, int32 l_ind { /* Find Index Mapping Vdata with Swath Attributes Vgroup */ snprintf(utlbuf, sizeof(utlbuf), "%s%s%s%s", "INDXMAP:", geodim, "/", datadim); - vgid = SWXSwath[swathID % idOffset].VIDTable[2]; + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + vgid = SWXSwath[sID].VIDTable[2]; vdataID = EHgetid(fid, vgid, utlbuf, 1, "r"); /* If found then get geodim size & read l_index mapping values */ @@ -1331,7 +1359,7 @@ SWcompinfo(int32 swathID, const char *fieldname, int32 * compcode, intn compparm /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWcompinfo", __FILE__, __LINE__); return(-1); } @@ -1343,7 +1371,13 @@ SWcompinfo(int32 swathID, const char *fieldname, int32 * compcode, intn compparm if (status == 0) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "DataField" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", @@ -1465,7 +1499,7 @@ SWcompinfo(int32 swathID, const char *fieldname, int32 * compcode, intn compparm free(metabuf); } free(utlstr); - + return (status); } @@ -1539,7 +1573,7 @@ SWfinfo(int32 swathID, const char *fieldtype, const char *fieldname, /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWfinfo", __FILE__, __LINE__); return(-1); } @@ -1553,14 +1587,20 @@ SWfinfo(int32 swathID, const char *fieldtype, const char *fieldname, status = SWchkswid(swathID, "SWfinfo", &fid, &sdInterfaceID, &dum); /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to appropriate "Field" section within SM */ if (strcmp(fieldtype, "Geolocation Fields") == 0) { metabuf = EHmetagroup(sdInterfaceID, swathname, "s", "GeoField", metaptrs); - + if(metabuf == NULL) { free(utlstr); @@ -1673,7 +1713,7 @@ SWfinfo(int32 swathID, const char *fieldtype, const char *fieldname, fsize = VSsizeof(vdataID, (char *)fieldname); buf = (uint8 *) calloc(fsize, 1); if(buf == NULL) - { + { HEpush(DFE_NOSPACE,"SWfinfo", __FILE__, __LINE__); free(utlstr); return(-1); @@ -1718,7 +1758,7 @@ SWfinfo(int32 swathID, const char *fieldtype, const char *fieldname, status = -1; } free(utlstr); - + return (status); } @@ -1887,7 +1927,12 @@ SWdefdimmap(int32 swathID, const char *geodim, const char *datadim, int32 offset metadata[0] = offset; metadata[1] = increment; - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); status = EHinsertmeta(sdInterfaceID, swathname, "s", 1L, mapname, metadata); @@ -1960,7 +2005,7 @@ SWdefidxmap(int32 swathID, const char *geodim, const char *datadim, int32 l_inde /* Geo Dimension Search */ /* -------------------- */ - + gsize = SWdiminfo(swathID, geodim); if (gsize == -1) @@ -1989,10 +2034,15 @@ SWdefidxmap(int32 swathID, const char *geodim, const char *datadim, int32 l_inde { /* Get attribute Vgroup ID and allocate data buffer */ /* ------------------------------------------------ */ - attrVgrpID = SWXSwath[swathID % idOffset].VIDTable[2]; + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + attrVgrpID = SWXSwath[sID].VIDTable[2]; buf = (uint8 *) calloc(4 * gsize, 1); if(buf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefidxmap", __FILE__, __LINE__); return(-1); } @@ -2022,9 +2072,10 @@ SWdefidxmap(int32 swathID, const char *geodim, const char *datadim, int32 l_inde /* Write to Structural Metadata */ snprintf(mapname, sizeof(mapname), "%s%s%s", geodim, "/", datadim); - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + Vgetname(SWXSwath[sID].IDTable, swathname); + int32 dumArray[1] = { dum }; status = EHinsertmeta(sdInterfaceID, swathname, "s", 2L, - mapname, &dum); + mapname, dumArray); } } @@ -2080,6 +2131,10 @@ SWdefcomp(int32 swathID, int32 compcode, intn compparm[]) if (status == 0) { sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } /* Set compression code in compression external array */ SWXSwath[sID].compcode = compcode; @@ -2220,12 +2275,16 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const { /* Remove offset from swath ID & get swathname */ sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } Vgetname(swVgrpID, swathname); /* Allocate space for dimbuf, copy dimlist into it, & append comma */ dimbuf = (char *) calloc(strlen(dimlist) + 64, 1); if(dimbuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefinefield", __FILE__, __LINE__); return(-1); } @@ -2245,7 +2304,7 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const /* Copy dimension list entry to dimcheck */ dimcheck = (char *) calloc(comma - dimbuf + 1, 1); if(dimcheck == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefinefield", __FILE__, __LINE__); free(dimbuf); return(-1); @@ -2325,7 +2384,7 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const { /* ((intn) strlen(fieldname) > MAX_NC_NAME - 7) ** this was changed because HDF4.1r3 made a change in the -** hlimits.h file. We have notified NCSA and asked to have +** hlimits.h file. We have notified NCSA and asked to have ** it made the same as in previous versions of HDF ** see ncr 26314. DaW Apr 2000 */ @@ -2473,7 +2532,7 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const */ oneDbuf = (uint8 *) calloc(recSize, 1); if(oneDbuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefinefield", __FILE__, __LINE__); return(-1); } @@ -2489,7 +2548,7 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const */ oneDbuf = (uint8 *) calloc(recSize, dims[0]); if(oneDbuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefinefield", __FILE__, __LINE__); return(-1); } @@ -2685,7 +2744,7 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const realloc((void *) SWXSwath[sID].sdsID, (SWXSwath[sID].nSDS + 1) * 4); if(SWXSwath[sID].sdsID == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefinefield", __FILE__, __LINE__); return(-1); } @@ -2695,7 +2754,7 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const { SWXSwath[sID].sdsID = (int32 *) calloc(1, 4); if(SWXSwath[sID].sdsID == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefinefield", __FILE__, __LINE__); return(-1); } @@ -2935,9 +2994,15 @@ SWwritegeometa(int32 swathID, const char *fieldname, const char *dimlist, /* ------------------------------ */ snprintf(utlbuf, sizeof(utlbuf), "%s%s%s", fieldname, ":", dimlist); - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); + int32 numbertypeArray[1] = { numbertype }; status = EHinsertmeta(sdInterfaceID, swathname, "s", 3L, - utlbuf, &numbertype); + utlbuf, numbertypeArray); } return (status); @@ -3000,9 +3065,15 @@ SWwritedatameta(int32 swathID, const char *fieldname, const char *dimlist, /* ------------------------------ */ snprintf(utlbuf, sizeof(utlbuf), "%s%s%s", fieldname, ":", dimlist); - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); + int32 numbertypeArray[1] = { numbertype }; status = EHinsertmeta(sdInterfaceID, swathname, "s", 4L, - utlbuf, &numbertype); + utlbuf, numbertypeArray); } return (status); } @@ -3061,7 +3132,12 @@ SWwrrdattr(int32 swathID, const char *attrname, int32 numbertype, int32 count, { /* Get attribute Vgroup ID and call EHattr to perform I/O */ /* ------------------------------------------------------ */ - attrVgrpID = SWXSwath[swathID % idOffset].VIDTable[2]; + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + attrVgrpID = SWXSwath[sID].VIDTable[2]; status = EHattr(fid, attrVgrpID, attrname, numbertype, count, wrcode, datbuf); } @@ -3213,7 +3289,12 @@ SWattrinfo(int32 swathID, const char *attrname, int32 * numbertype, int32 * coun { /* Get attribute Vgroup ID and call EHattrinfo */ /* ------------------------------------------- */ - attrVgrpID = SWXSwath[swathID % idOffset].VIDTable[2]; + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + attrVgrpID = SWXSwath[sID].VIDTable[2]; status = EHattrinfo(fid, attrVgrpID, attrname, numbertype, count); @@ -3278,7 +3359,12 @@ SWinqattrs(int32 swathID, char *attrnames, int32 * strbufsize) { /* Get attribute Vgroup ID and call EHattrcat */ /* ------------------------------------------ */ - attrVgrpID = SWXSwath[swathID % idOffset].VIDTable[2]; + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } + attrVgrpID = SWXSwath[sID].VIDTable[2]; nattr = EHattrcat(fid, attrVgrpID, attrnames, strbufsize); } @@ -3349,7 +3435,7 @@ SWinqdims(int32 swathID, char *dimnames, int32 dims[]) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWinqdims", __FILE__, __LINE__); return(-1); } @@ -3364,7 +3450,13 @@ SWinqdims(int32 swathID, char *dimnames, int32 dims[]) if (dimnames != NULL || dims != NULL) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "Dimension" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", @@ -3514,7 +3606,7 @@ SWinqmaps(int32 swathID, char *dimmaps, int32 offset[], int32 increment[]) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWinqmaps", __FILE__, __LINE__); return(-1); } @@ -3529,7 +3621,13 @@ SWinqmaps(int32 swathID, char *dimmaps, int32 offset[], int32 increment[]) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "DimensionMap" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", @@ -3680,7 +3778,7 @@ SWinqidxmaps(int32 swathID, char *idxmaps, int32 idxsizes[]) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWinqidxmaps", __FILE__, __LINE__); return(-1); } @@ -3695,7 +3793,13 @@ SWinqidxmaps(int32 swathID, char *idxmaps, int32 idxsizes[]) if (idxmaps != NULL || idxsizes != NULL) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "IndexDimensionMap" section within SM */ metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", @@ -3744,7 +3848,7 @@ SWinqidxmaps(int32 swathID, char *idxmaps, int32 idxsizes[]) { /* Parse off geo dimension and find its size */ slash = strchr(utlstr, '/'); - *slash = 0; + if (slash) *slash = 0; idxsizes[nMap] = SWdiminfo(swathID, utlstr); } @@ -3844,14 +3948,14 @@ SWinqfields(int32 swathID, const char *fieldtype, char *fieldlist, int32 rank[], /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWinqfields", __FILE__, __LINE__); return(-1); } utlstr2 = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr2 == NULL) - { + { HEpush(DFE_NOSPACE,"SWinqfields", __FILE__, __LINE__); free(utlstr); return(-1); @@ -3868,7 +3972,14 @@ SWinqfields(int32 swathID, const char *fieldtype, char *fieldlist, int32 rank[], if (fieldlist != NULL || rank != NULL || numbertype != NULL) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + free(utlstr2); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "GeoField" or "DataField" section within SM */ if (strcmp(fieldtype, "Geolocation Fields") == 0) @@ -4153,7 +4264,7 @@ SWnentries(int32 swathID, int32 entrycode, int32 * strbufsize) /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWnemtries", __FILE__, __LINE__); return(-1); } @@ -4164,7 +4275,13 @@ SWnentries(int32 swathID, int32 entrycode, int32 * strbufsize) if (status == 0) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstr); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Zero out string buffer size */ *strbufsize = 0; @@ -4420,7 +4537,10 @@ SW1dfldsrch(int32 fid, int32 swathID, const char *fieldname, const char *i_acces /* Compute "reduced" swath ID */ /* -------------------------- */ sID = swathID % idOffset; - + if (sID >= NSWATH) + { + return -1; + } /* Get Geolocation Vgroup id and 1D field name Vdata id */ /* ---------------------------------------------------- */ @@ -4520,7 +4640,7 @@ SWSDfldsrch(int32 swathID, int32 sdInterfaceID, const char *fieldname, /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) - { + { HEpush(DFE_NOSPACE,"SWSDfldsrch", __FILE__, __LINE__); return(-1); } @@ -4532,7 +4652,10 @@ SWSDfldsrch(int32 swathID, int32 sdInterfaceID, const char *fieldname, /* Compute "reduced" swath ID */ /* -------------------------- */ sID = swathID % idOffset; - + if (sID >= NSWATH) + { + return -1; + } /* Loop through all SDSs in swath */ /* ------------------------------ */ @@ -4982,7 +5105,7 @@ SWwrrdfield(int32 swathID, const char *fieldname, const char *code, fldsize = VSsizeof(vdataID, (char *)fieldname); fillbuf = (uint8 *) calloc(fldsize, 1); if(fillbuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWwrrdfield", __FILE__, __LINE__); return(-1); } @@ -4992,8 +5115,9 @@ SWwrrdfield(int32 swathID, const char *fieldname, const char *code, VSQueryvsize(vdataID, &recsize); buf = (uint8 *) calloc(recsize, count[0] * incr[0]); if(buf == NULL) - { + { HEpush(DFE_NOSPACE,"SWwrrdfield", __FILE__, __LINE__); + free(fillbuf); return(-1); } @@ -5096,7 +5220,7 @@ SWwrrdfield(int32 swathID, const char *fieldname, const char *code, fldsize = VSsizeof(vdataID, (char *)fieldname); buf = (uint8 *) calloc(fldsize, count[0] * incr[0]); if(buf == NULL) - { + { HEpush(DFE_NOSPACE,"SWwrrdfield", __FILE__, __LINE__); return(-1); } @@ -5289,7 +5413,7 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], intn i; /* Loop index */ intn j = 0; /* Loop index */ intn k; /* Loop index */ - + intn status; /* routine return status variable */ intn statLon; /* Status from SWfieldinfo for longitude */ intn statLat; /* Status from SWfieldinfo for latitude */ @@ -5300,8 +5424,8 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], uint8 found = 0; /* Found flag */ uint8 *flag; /* Pointer to track flag array */ - intn validReg = -1; /* -1 is invalid validReg */ - + intn validReg = -1; /* -1 is invalid validReg */ + int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 swVgrpID; /* Swath Vgroup ID */ @@ -5330,7 +5454,7 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], char dimlist[256]; /* Dimension list (geolocation * fields) */ char latName[17];/* Latitude field name */ - + /* Check for valid swath ID */ /* ------------------------ */ @@ -5371,9 +5495,9 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], dimlist); if (statCoLat != 0) { - /* Check again for Geodeticlatitude */ - statGeodeticLat = SWfieldinfo(swathID, - "GeodeticLatitude", &rank, + /* Check again for Geodeticlatitude */ + statGeodeticLat = SWfieldinfo(swathID, + "GeodeticLatitude", &rank, dims, &nt, dimlist); if (statGeodeticLat != 0) { @@ -5464,14 +5588,14 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* --------------------------------------------------- */ lonArr = (char *) calloc(nElem, sizeof(float64)); if(lonArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefboxregion", __FILE__, __LINE__); return(-1); } latArr = (char *) calloc(nElem, sizeof(float64)); if(latArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefboxregion", __FILE__, __LINE__); free(lonArr); return(-1); @@ -5482,7 +5606,7 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* ------------------------------------- */ flag = (uint8 *) calloc(edge[0] + 1, 1); if(flag == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefboxregion", __FILE__, __LINE__); free(lonArr); free(latArr); @@ -5515,7 +5639,7 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], temp64 = (float64) temp32; memcpy(latArr + 8 * i, &temp64, 8); } - } + } /* Set boundary flag */ @@ -5536,7 +5660,7 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* ------------------ */ for (i = 0; i < edge[0]; i++) - { + { /* For each value from Cross Track ... */ /* ----------------------------------- */ for (j = 0; j < edge[1]; j++) @@ -5611,16 +5735,18 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* ----------------------------------------------- */ lonArr = (char *) calloc(dims[1], sizeof(float64)); if(lonArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefboxregion", __FILE__, __LINE__); + free(flag); return(-1); } latArr = (char *) calloc(dims[1], sizeof(float64)); if(latArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefboxregion", __FILE__, __LINE__); free(lonArr); + free(flag); return(-1); } @@ -5630,13 +5756,13 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], anyStart[1] = 0; anyEdge[0] = 1; anyEdge[1] = dims[1]; - - + + /* For each track starting from 0 */ /* ------------------------------ */ - for (i = 0; i < edge[0]; i++) + for (i = 0; i < edge[0]; i++) { - + /* If cross track not in region (with MIDPOINT search ... */ /* ------------------------------------------------------ */ if (flag[i] == 0) @@ -5755,8 +5881,11 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], SWXRegion[k] = (struct swathRegion *) calloc(1, sizeof(struct swathRegion)); if(SWXRegion[k] == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefboxregion", __FILE__, __LINE__); + free(lonArr); + free(latArr); + free(flag); return(-1); } @@ -5786,9 +5915,11 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], if (k >= NSWATHREGN) { HEpush(DFE_GENAPP, "SWdefboxregion", __FILE__, __LINE__); - HEreport( - "regionID exceeded NSWATHREGN.\n"); - return (-1); + HEreport("regionID exceeded NSWATHREGN.\n"); + free(lonArr); + free(latArr); + free(flag); + return (-1); } /* Find start and stop of regions */ @@ -5816,10 +5947,10 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* Increment (multiple) region counter */ /* ----------------------------------- */ j = ++SWXRegion[k]->nRegions; - + /* if SWXRegion[k]->nRegions greater than MAXNREGIONS */ /* free allocated memory and return FAIL */ - + if ((SWXRegion[k]->nRegions) > MAXNREGIONS) { HEpush(DFE_GENAPP, "SWdefboxregion", __FILE__, __LINE__); @@ -5829,10 +5960,10 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], free(flag); return(-1); } - + SWXRegion[k]->StartRegion[j - 1] = i; } - + /* End of region */ /* ------------- */ if (flag[i] == 255) @@ -5855,7 +5986,7 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], { return (-1); } - + } @@ -5920,8 +6051,8 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], uint8 found = 0; /* Found flag */ uint8 *flag; /* Pointer to track flag array */ - intn validReg = -1; /* -1 is invalid validReg */ - + intn validReg = -1; /* -1 is invalid validReg */ + int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 swVgrpID; /* Swath Vgroup ID */ @@ -5991,9 +6122,9 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], dimlist); if (statCoLat != 0) { - /* Check again for Geodeticlatitude */ - statGeodeticLat = SWfieldinfo(swathID, - "GeodeticLatitude", &rank, + /* Check again for Geodeticlatitude */ + statGeodeticLat = SWfieldinfo(swathID, + "GeodeticLatitude", &rank, dims, &nt, dimlist); if (statGeodeticLat != 0) { @@ -6089,14 +6220,14 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* --------------------------------------------------- */ lonArr = (char *) calloc(nElem, sizeof(float64)); if(lonArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWregionl_index", __FILE__, __LINE__); return(-1); } - + latArr = (char *) calloc(nElem, sizeof(float64)); if(latArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWregionl_index", __FILE__, __LINE__); free(lonArr); return(-1); @@ -6107,7 +6238,7 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* ------------------------------------- */ flag = (uint8 *) calloc(edge[0] + 1, 1); if(flag == NULL) - { + { HEpush(DFE_NOSPACE,"SWregionl_index", __FILE__, __LINE__); free(lonArr); free(latArr); @@ -6235,13 +6366,13 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* ----------------------------------------------- */ lonArr = (char *) calloc(dims[1], sizeof(float64)); if(lonArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWregionl_index", __FILE__, __LINE__); return(-1); } latArr = (char *) calloc(dims[1], sizeof(float64)); if(latArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWregionl_index", __FILE__, __LINE__); free(lonArr); return(-1); @@ -6382,8 +6513,11 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], SWXRegion[k] = (struct swathRegion *) calloc(1, sizeof(struct swathRegion)); if(SWXRegion[k] == NULL) - { + { HEpush(DFE_NOSPACE,"SWregionl_index", __FILE__, __LINE__); + free(lonArr); + free(latArr); + free(flag); return(-1); } @@ -6457,7 +6591,7 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], /* Increment (multiple) region counter */ /* ----------------------------------- */ j = ++SWXRegion[k]->nRegions; - + if (mapstatus == 2) { l = i; @@ -6478,7 +6612,7 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], validReg = 0; } } - + } } @@ -6495,7 +6629,7 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], { return (-1); } - + } @@ -6614,7 +6748,7 @@ SWdeftimeperiod(int32 swathID, float64 starttime, float64 stoptime, /* ---------------------------- */ time64 = (float64 *) calloc(edge[0], 8); if(time64 == NULL) - { + { HEpush(DFE_NOSPACE,"SWdeftimeperiod", __FILE__, __LINE__); return(-1); } @@ -6639,7 +6773,7 @@ SWdeftimeperiod(int32 swathID, float64 starttime, float64 stoptime, /* ---------------------------- */ time64 = (float64 *) calloc(edge[0] * 2, 8); if(time64 == NULL) - { + { HEpush(DFE_NOSPACE,"SWdeftimeperiod", __FILE__, __LINE__); return(-1); } @@ -6691,7 +6825,7 @@ SWdeftimeperiod(int32 swathID, float64 starttime, float64 stoptime, SWXRegion[k] = (struct swathRegion *) calloc(1, sizeof(struct swathRegion)); if(SWXRegion[k] == NULL) - { + { HEpush(DFE_NOSPACE,"SWdeftimeperiod", __FILE__, __LINE__); return(-1); } @@ -6743,45 +6877,47 @@ SWdeftimeperiod(int32 swathID, float64 starttime, float64 stoptime, } - - /* Clear found flag */ - /* ---------------- */ - found = 0; + if (periodID >= 0) + { + /* Clear found flag */ + /* ---------------- */ + found = 0; - /* For each track (from bottom) ... */ - /* -------------------------------- */ - for (i = edge[0] - 1; i >= 0; i--) - { - /* For each value from Cross Track ... */ - /* ----------------------------------- */ - for (j = 0; j < edge[1]; j++) + /* For each track (from bottom) ... */ + /* -------------------------------- */ + for (i = edge[0] - 1; i >= 0; i--) { + /* For each value from Cross Track ... */ + /* ----------------------------------- */ + for (j = 0; j < edge[1]; j++) + { - /* Get time test value */ - /* ------------------- */ - time64Test = time64[i * edge[1] + j]; + /* Get time test value */ + /* ------------------- */ + time64Test = time64[i * edge[1] + j]; - /* If within time period ... */ - /* ------------------------- */ - if (time64Test >= starttime && - time64Test <= stoptime) - { - /* Set found flag */ - /* -------------- */ - found = 1; + /* If within time period ... */ + /* ------------------------- */ + if (time64Test >= starttime && + time64Test <= stoptime) + { + /* Set found flag */ + /* -------------- */ + found = 1; - /* Set start of region to first track found */ - /* ---------------------------------------- */ - SWXRegion[k]->StopRegion[0] = i; + /* Set start of region to first track found */ + /* ---------------------------------------- */ + SWXRegion[periodID]->StopRegion[0] = i; - break; /* Break from "j" loop */ + break; /* Break from "j" loop */ + } + } + if (found == 1) + { + break; /* Break from "i" loop */ } - } - if (found == 1) - { - break; /* Break from "i" loop */ } } @@ -7059,7 +7195,7 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, { /* If non-vertical subset regions defined ... */ /* ------------------------------------------ */ - if (SWXRegion[regionID]->nRegions > 0) + if (SWXRegion[regionID]->nRegions > 0) { /* Get geolocation dimension name */ @@ -7078,7 +7214,7 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, status = SWfieldinfo(SWXRegion[regionID]->swathID, "Time", &dum, dumdims, &dum, tgeodim); - + if (strcmp(geodim, tgeodim) != 0) { strcpy(geodim, tgeodim); @@ -7183,6 +7319,10 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, /* Get size of geo dim & allocate space of l_index mapping */ /* ----------------------------------------------------- */ dum = SWdiminfo(swathID, geodim); + if( dum < 0 ) + { + return -1; + } /* For Landsat files, the l_index mapping has two values */ /* for each point, a left and right point. So for a 37 */ @@ -7192,14 +7332,14 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, /* dimension. */ /* ----------------------------------------------------- */ if(land_status == 0) - if(strcmp(fieldname, "Latitude") == 0 || + if(strcmp(fieldname, "Latitude") == 0 || strcmp(fieldname, "Longitude") == 0) { dum = dum * 2; } idxmap = (int32 *) calloc(dum, sizeof(int32)); if(idxmap == NULL) - { + { HEpush(DFE_NOSPACE,"SWextractregion", __FILE__, __LINE__); return(-1); } @@ -7270,7 +7410,7 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, if (SWXRegion[regionID]->scanflag == 1) { start[l_index] = SWXRegion[regionID]->StartRegion[k]/incr; - if(SWXRegion[regionID]->band8flag == 2 || + if(SWXRegion[regionID]->band8flag == 2 || SWXRegion[regionID]->band8flag == 3) { start[l_index] = (SWXRegion[regionID]->StartRegion[k]+detect_cnt)/incr; @@ -7452,7 +7592,7 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, if(idxmap[j] == 0 || idxmap[j+1] == 0) l = scene_cnt; } - + } } @@ -7531,11 +7671,11 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, } else { - if (SWXRegion[regionID]->scanflag == 1 && + if (SWXRegion[regionID]->scanflag == 1 && strcmp(fieldname,dfieldlist) == 0) { start[l_index] = SWXRegion[regionID]->StartRegion[k]; - edge[l_index] = SWXRegion[regionID]->StopRegion[k] - + edge[l_index] = SWXRegion[regionID]->StopRegion[k] - SWXRegion[regionID]->StartRegion[k] + 1; if(SWXRegion[regionID]->band8flag == 2 || SWXRegion[regionID]->band8flag == 3 ) @@ -7562,15 +7702,15 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, buffer); if (SWXRegion[regionID]->scanflag == 1) { - + if (strcmp(fieldname,"Longitude") == 0) { - status = SWscan2longlat(swathID, fieldname, buffer, start, + status = SWscan2longlat(swathID, fieldname, buffer, start, edge, idxmap, startscanline, stopscanline); } if (strcmp(fieldname,"Latitude") == 0) { - status = SWscan2longlat(swathID, fieldname, buffer, start, + status = SWscan2longlat(swathID, fieldname, buffer, start, edge, idxmap, startscanline, stopscanline); } } @@ -7586,11 +7726,11 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, { /* Mapping not found */ /* ----------------- */ - status = -1; + status = -1; HEpush(DFE_GENAPP, "SWextractregion", __FILE__, __LINE__); HEreport("Mapping Not Defined for \"%s\" Dimension.\n", geodim); - } + } } else { @@ -7652,7 +7792,7 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, | END_PROLOG | -----------------------------------------------------------------------------*/ static intn -SWscan2longlat(int32 swathID, const char *fieldname, VOIDP buffer, int32 start[], +SWscan2longlat(int32 swathID, const char *fieldname, VOIDP buffer, int32 start[], int32 edge[], int32 *idxmap, int32 startscanline, int32 stopscanline) { @@ -7863,14 +8003,14 @@ int32 edge[], int32 *idxmap, int32 startscanline, int32 stopscanline) y_p1 = (float)(RADOE * sin((p1_long*deg2rad)) * sin((p1_lat*deg2rad))); z_p1 = (float)(RADOE * cos((p1_lat*deg2rad))); - + x_p2 = (float)(RADOE * cos((p2_long*deg2rad)) * sin((p2_lat*deg2rad))); y_p2 = (float)(RADOE * sin((p2_long*deg2rad)) * sin((p2_lat*deg2rad))); z_p2 = (float)(RADOE * cos((p2_lat*deg2rad))); x_pi = x_p1 + (x_p2 - x_p1)*(scanline_pi-scanline_p1)/(scanline_p2-scanline_p1); y_pi = y_p1 + (y_p2 - y_p1)*(scanline_pi-scanline_p1)/(scanline_p2-scanline_p1); - z_pi = z_p1 + (z_p2 - z_p1)*(scanline_pi-scanline_p1)/(scanline_p2-scanline_p1); + z_pi = z_p1 + (z_p2 - z_p1)*(scanline_pi-scanline_p1)/(scanline_p2-scanline_p1); if (fieldflag == 1) { @@ -8071,7 +8211,7 @@ SWdupregion(int32 oldregionID) SWXRegion[i] = (struct swathRegion *) calloc(1, sizeof(struct swathRegion)); if(SWXRegion[i] == NULL) - { + { HEpush(DFE_NOSPACE,"SWdupregion", __FILE__, __LINE__); return(-1); } @@ -8143,7 +8283,7 @@ SWregioninfo(int32 swathID, int32 regionID, const char *fieldname, intn long_status = 3; /* routine return status variable for longitude */ intn land_status = 3; /* Used for L7 float scene sub. */ intn statMap = -1; /* Status from SWmapinfo */ - + uint8 found = 0; /* Found flag */ uint8 detect_cnt = 0; /* Used for L7 float scene sub. */ @@ -8292,7 +8432,7 @@ SWregioninfo(int32 swathID, int32 regionID, const char *fieldname, status = SWfieldinfo(SWXRegion[regionID]->swathID, "Time", &dum, dumdims, &dum, tgeodim); - + if (strcmp(geodim, tgeodim) != 0) { strcpy(geodim, tgeodim); @@ -8381,9 +8521,11 @@ SWregioninfo(int32 swathID, int32 regionID, const char *fieldname, /* Get size of geo dim & allocate space of l_index mapping */ /* ----------------------------------------------------- */ dum = SWdiminfo(swathID, geodim); + if (dum < 0) + return -1; idxmap = (int32 *) calloc(dum, sizeof(int32)); if(idxmap == NULL) - { + { HEpush(DFE_NOSPACE,"SWregioninfo", __FILE__, __LINE__); return(-1); } @@ -8667,7 +8809,7 @@ SWregioninfo(int32 swathID, int32 regionID, const char *fieldname, { /* Mapping not found */ /* ----------------- */ - status = -1; + status = -1; HEpush(DFE_GENAPP, "SWregioninfo", __FILE__, __LINE__); HEreport( @@ -8858,6 +9000,7 @@ SWperiodinfo(int32 swathID, int32 periodID, const char *fieldname, #define SETSWTHREG \ \ +regionID = 0; \ for (k = 0; k < NSWATHREGN; k++) \ { \ if (SWXRegion[k] == 0) \ @@ -8985,7 +9128,7 @@ SWdefvrtregion(int32 swathID, int32 regionID, const char *vertObj, float64 range SWXRegion[regionID]->DimNamePtr[j] = (char *) malloc(slen + 1); if(SWXRegion[regionID]->DimNamePtr[j] == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefvrtregion", __FILE__, __LINE__); return(-1); } @@ -9062,7 +9205,7 @@ SWdefvrtregion(int32 swathID, int32 regionID, const char *vertObj, float64 range /* --------------------------------- */ vertArr = (char *) calloc(dims[0], size); if(vertArr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdefvrtregion", __FILE__, __LINE__); return(-1); } @@ -9909,6 +10052,10 @@ SWdetach(int32 swathID) /* Subtract off swath ID offset and get swath name */ /* ----------------------------------------------- */ sID = swathID % idOffset; + if (sID >= NSWATH) + { + return -1; + } Vgetname(SWXSwath[sID].IDTable, swathname); @@ -9933,7 +10080,7 @@ SWdetach(int32 swathID) /* ---------------------------- */ nambuf = (char *) calloc(VSNAMELENMAX + 1, 1); if(nambuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); return(-1); } @@ -9948,7 +10095,7 @@ SWdetach(int32 swathID) /* --------------------- */ buf = (uint8 *) calloc(VSsizeof(vdataID, nambuf), dims[0]); if(buf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nambuf); return(-1); @@ -9976,20 +10123,20 @@ SWdetach(int32 swathID) /* ---------------------------------------------------- */ nameptr = (char **) calloc(1, sizeof(char *)); if(nameptr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); return(-1); } namelen = (int32 *) calloc(1, sizeof(int32)); if(namelen == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); return(-1); } nameptr0 = (char **) calloc(1, sizeof(char *)); if(nameptr0 == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -9997,7 +10144,7 @@ SWdetach(int32 swathID) } namelen0 = (int32 *) calloc(1, sizeof(int32)); if(namelen0 == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10006,7 +10153,7 @@ SWdetach(int32 swathID) } dimptr = (char **) calloc(1, sizeof(char *)); if(dimptr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10016,7 +10163,7 @@ SWdetach(int32 swathID) } dimlen = (int32 *) calloc(1, sizeof(int32)); if(dimlen == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10027,7 +10174,7 @@ SWdetach(int32 swathID) } offset = (int32 *) calloc(1, sizeof(int32)); if(offset == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10039,7 +10186,7 @@ SWdetach(int32 swathID) } indvdims = (int32 *) calloc(1, sizeof(int32)); if(indvdims == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10048,7 +10195,7 @@ SWdetach(int32 swathID) free(dimptr); free(dimlen); free(offset); - return(-1); + return(-1); } } else @@ -10070,20 +10217,20 @@ SWdetach(int32 swathID) /* ----------------------------------------- */ nameptr = (char **) calloc(nflds, sizeof(char *)); if(nameptr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); return(-1); } namelen = (int32 *) calloc(nflds, sizeof(int32)); if(namelen == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); return(-1); } nameptr0 = (char **) calloc(nflds, sizeof(char *)); if(nameptr0 == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10091,7 +10238,7 @@ SWdetach(int32 swathID) } namelen0 = (int32 *) calloc(nflds, sizeof(int32)); if(namelen0 == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10100,7 +10247,7 @@ SWdetach(int32 swathID) } dimptr = (char **) calloc(nflds, sizeof(char *)); if(dimptr == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10110,7 +10257,7 @@ SWdetach(int32 swathID) } dimlen = (int32 *) calloc(nflds, sizeof(int32)); if(dimlen == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10121,7 +10268,7 @@ SWdetach(int32 swathID) } offset = (int32 *) calloc(nflds, sizeof(int32)); if(offset == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10133,7 +10280,7 @@ SWdetach(int32 swathID) } indvdims = (int32 *) calloc(nflds, sizeof(int32)); if(indvdims == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nameptr); free(namelen); @@ -10142,7 +10289,7 @@ SWdetach(int32 swathID) free(dimptr); free(dimlen); free(offset); - return(-1); + return(-1); } @@ -10164,15 +10311,31 @@ SWdetach(int32 swathID) { nambuf = (char *) calloc(strlen(SWXSDname) + 1, 1); if(nambuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); + free(nameptr); + free(namelen); + free(nameptr0); + free(namelen0); + free(dimptr); + free(dimlen); + free(offset); + free(indvdims); return(-1); } utlbuf = (char *) calloc(2 * strlen(SWXSDname) + 7, 1); if(utlbuf == NULL) - { + { HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__); free(nambuf); + free(nameptr); + free(namelen); + free(nameptr0); + free(namelen0); + free(dimptr); + free(dimlen); + free(offset); + free(indvdims); return(-1); } /* Zero out dimbuf1 */ @@ -10637,16 +10800,16 @@ SWupdatescene(int32 swathID, int32 regionID) { intn k; /* Loop index */ int32 status; /* routine return status variable */ - + int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 swVgrpID; /* Swath Vgroup ID */ - + int32 startReg; /* Indexed start region */ int32 stopReg; /* Indexed stop region */ - int32 l_index[MAXNREGIONS]; /* to store indices when stop and + int32 l_index[MAXNREGIONS]; /* to store indices when stop and start are different */ - + int32 ind; /* l_index */ int32 tempnRegions; /* temp number of regions */ @@ -10656,8 +10819,8 @@ SWupdatescene(int32 swathID, int32 regionID) /* ------------------------ */ status = SWchkswid(swathID, "SWupdatescene", &fid, &sdInterfaceID, &swVgrpID); - - + + /* Check for valid region ID */ /* ------------------------- */ if (status == 0) @@ -10669,7 +10832,7 @@ SWupdatescene(int32 swathID, int32 regionID) HEreport("Invalid Region id: %d.\n", regionID); } } - + /* Check for active region ID */ /* -------------------------- */ if (status == 0) @@ -10681,12 +10844,12 @@ SWupdatescene(int32 swathID, int32 regionID) HEreport("Inactive Region ID: %d.\n", regionID); } } - + if (status == 0) { tempnRegions = SWXRegion[regionID]->nRegions; ind =0; - + for (k = 0; k < SWXRegion[regionID]->nRegions; k++) { startReg = SWXRegion[regionID]->StartRegion[k]; @@ -10696,10 +10859,10 @@ SWupdatescene(int32 swathID, int32 regionID) /* reduce number of regions by 1, if tempnRegions is 0 issue error and break from loop*/ tempnRegions -= 1; - + if(tempnRegions == 0) { - /* first free allocated memory for SWXRegion[regionID] + /* first free allocated memory for SWXRegion[regionID] in the function SWdefboxregion and make regionID inactive */ free(SWXRegion[regionID]); @@ -10726,7 +10889,7 @@ SWupdatescene(int32 swathID, int32 regionID) { SWXRegion[regionID]->nRegions = tempnRegions; } - /* keep starts and stops that are different in the structure */ + /* keep starts and stops that are different in the structure */ for (k = 0; k < SWXRegion[regionID]->nRegions; k++) { SWXRegion[regionID]->StartRegion[k] = @@ -10734,36 +10897,36 @@ SWupdatescene(int32 swathID, int32 regionID) SWXRegion[regionID]->StopRegion[k] = SWXRegion[regionID]->StopRegion[l_index[k]]; } - + } - + if (status == 0) { - + for (k = 0; k < SWXRegion[regionID]->nRegions; k++) { - + startReg = SWXRegion[regionID]->StartRegion[k]; stopReg = SWXRegion[regionID]->StopRegion[k]; - + if(startReg % 2 == 1) { - + SWXRegion[regionID]->StartRegion[k] = ++startReg; - + } if(stopReg % 2 == 0) { - + SWXRegion[regionID]->StopRegion[k] = --stopReg; - + } - + } - + } - + return(status); - + } /*----------------------------------------------------------------------------| @@ -10807,14 +10970,14 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou intn k; /* Loop index */ int32 status; /* routine return status variable */ int32 land_status = 3; /* routine return status variable */ - + int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 swVgrpID; /* Swath Vgroup ID */ int32 numtype = 0; /* Used for L7 float scene sub. */ int32 count = 0; /* Used for L7 float scene sub. */ - + int32 startReg = 0; /* Indexed start region */ int32 stopReg = 0; /* Indexed stop region */ int32 nout=-1; /* Number of elements in output l_index array */ @@ -10825,13 +10988,13 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou intn ngtflag = 0; int32 *buffer1 = (int32 *)NULL; int32 *buffer2 = (int32 *)NULL; - + /* Check for valid swath ID */ /* ------------------------ */ status = SWchkswid(swathID, "SWupdateidxmap", &fid, &sdInterfaceID, &swVgrpID); - - + + /* Check for valid region ID */ /* ------------------------- */ if (status == 0) @@ -10843,7 +11006,7 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou HEreport("Invalid Region id: %d.\n", regionID); } } - + /* Check for active region ID */ /* -------------------------- */ if (status == 0) @@ -10855,20 +11018,20 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou HEreport("Inactive Region ID: %d.\n", regionID); } } - + if (status == 0) { /* Loop through all regions */ /* ------------------------ */ for (k = 0; k < SWXRegion[regionID]->nRegions; k++) { - + /* fix overlap l_index mapping problem for Landsat 7 */ - + startReg = SWXRegion[regionID]->StartRegion[k]; stopReg = SWXRegion[regionID]->StopRegion[k]; - - + + if(SWXRegion[regionID]->scanflag == 1) { indicies[0] = -1; @@ -10885,16 +11048,16 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou land_status = SWreadattr(swathID, "detector_count", &detect_cnt); } - + /* calculate the offsets first */ buffer1 = (int32 *)calloc(74, sizeof(int32)); buffer2 = (int32 *)calloc(74, sizeof(int32)); - + status = SWidxmapinfo(swathID,"GeoTrack", "ScanLineTrack", (int32*)buffer1); status = SWidxmapinfo(swathID,"UpperTrack", "ScanLineTrack", (int32*)buffer2); - + indexoffset = buffer2[0] - buffer1[0]; free(buffer1); free(buffer2); @@ -10973,11 +11136,11 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou { for(i=0; i= (l_indexin[j] + indexoffset - detect_cnt) && + if( startReg >= (l_indexin[j] + indexoffset - detect_cnt) && startReg <= (l_indexin[j+1] + indexoffset - detect_cnt) ) if(indicies[0] == -1) indicies[0] = j; - if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && + if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && stopReg <= (l_indexin[j+1] + indexoffset - detect_cnt ) ) indicies[1] = j + 1; j = j + 2; @@ -10993,7 +11156,7 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou if(SWXRegion[regionID]->band8flag == 2 || SWXRegion[regionID]->band8flag == 3) { - + if(startReg >= (l_indexin[j - 1] + indexoffset - detect_cnt)) { indicies[0] = -1; @@ -11008,11 +11171,11 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou j = 0; for(i=0; i= (l_indexin[j] + indexoffset - detect_cnt) && + if( startReg >= (l_indexin[j] + indexoffset - detect_cnt) && startReg <= (l_indexin[j+1] + indexoffset - detect_cnt) ) if(indicies[0] == -1) indicies[0] = j; - if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && + if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && stopReg <= (l_indexin[j+1] + indexoffset - detect_cnt ) ) indicies[1] = j + 1; j = j + 2; @@ -11026,11 +11189,11 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou j = 0; for(i=0; i= (l_indexin[j] + indexoffset - detect_cnt) && + if( startReg >= (l_indexin[j] + indexoffset - detect_cnt) && startReg <= (l_indexin[j+1] + indexoffset - detect_cnt) ) if(indicies[0] == -1) indicies[0] = j; - + j = j + 2; if(l_indexin[j] == 0 || l_indexin[j+1] == 0) i = scene_cnt; @@ -11045,7 +11208,7 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou j = 0; for(i=0; i= (l_indexin[j] + indexoffset - detect_cnt ) && + if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && stopReg <= (l_indexin[j+1] + indexoffset - detect_cnt ) ) indicies[1] = j; j = j + 2; @@ -11146,14 +11309,14 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou j = 0; for(i=0;i= (l_indexin[j] + indexoffset - detect_cnt ) && + if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && stopReg <= (l_indexin[j+1] + indexoffset - detect_cnt ) ) indicies[1] = j; j = j + 2; if(l_indexin[j] == 0 || l_indexin[j+1] == 0) i = scene_cnt; } - } + } } if(startReg > (l_indexin[j - 1] + indexoffset - detect_cnt )) @@ -11170,11 +11333,11 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou j = 0; for(i=0; i= (l_indexin[j] + indexoffset - detect_cnt) && + if( startReg >= (l_indexin[j] + indexoffset - detect_cnt) && startReg <= (l_indexin[j+1] + indexoffset - detect_cnt) ) if(indicies[0] == -1) indicies[0] = j; - if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && + if( stopReg >= (l_indexin[j] + indexoffset - detect_cnt ) && stopReg <= (l_indexin[j+1] + indexoffset - detect_cnt ) ) indicies[1] = j + 1; j = j + 2; @@ -11199,7 +11362,7 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou { startReg++; } - + /* If end of region is even then decrement */ /* --------------------------------------- */ if (stopReg % 2 == 0) @@ -11211,9 +11374,9 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou indicies[1]=stopReg; } } - + if (l_indexout != NULL) - { + { if(SWXRegion[regionID]->scanflag == 1) { nout = (indicies[1] - indicies[0] + 1); @@ -11241,17 +11404,17 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou nout = indicies[1] - indicies[0] + 1; } } - - + + if(status == -1) - { + { return(status); } else { return(nout); } - + } @@ -11293,7 +11456,7 @@ SWgeomapinfo(int32 swathID, const char *geodim) { intn status; /* routine return status variable */ - + int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 swVgrpID; /* Swath root Vgroup ID */ @@ -11306,19 +11469,19 @@ SWgeomapinfo(int32 swathID, const char *geodim) char swathname[80]; /* Swath Name */ char *utlstrr; /* Utility string */ char *utlstri; /* Utility string */ - - + + /* Allocate space for utility string */ /* --------------------------------- */ utlstrr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstrr == NULL) - { + { HEpush(DFE_NOSPACE,"SWgeomapinfo", __FILE__, __LINE__); return(-1); } utlstri = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstri == NULL) - { + { HEpush(DFE_NOSPACE,"SWgeomapinfo", __FILE__, __LINE__); free(utlstrr); return(-1); @@ -11330,7 +11493,14 @@ SWgeomapinfo(int32 swathID, const char *geodim) if (status == 0) { /* Get swath name */ - Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); + int sID = swathID % idOffset; + if (sID >= NSWATH) + { + free(utlstrr); + free(utlstri); + return -1; + } + Vgetname(SWXSwath[sID].IDTable, swathname); /* Get pointers to "DimensionMap" section within SM */ metabufr = EHmetagroup(sdInterfaceID, swathname, "s", @@ -11346,7 +11516,7 @@ SWgeomapinfo(int32 swathID, const char *geodim) snprintf(utlstrr, UTLSTR_MAX_SIZE, "%s%s%s", "\t\t\t\tGeoDimension=\"", geodim, "\"\n\t\t\t\tDataDimension="); metaptrsr[0] = strstr(metaptrsr[0], utlstrr); - + /* Get pointers to "IndexDimensionMap" section within SM */ metabufi = EHmetagroup(sdInterfaceID, swathname, "s", "IndexDimensionMap", metaptrsi); @@ -11367,12 +11537,12 @@ SWgeomapinfo(int32 swathID, const char *geodim) */ if (metaptrsr[0] < metaptrsr[1] && metaptrsr[0] != NULL) { - status = status + 1; + status = status + 1; } if (metaptrsi[0] < metaptrsi[1] && metaptrsi[0] != NULL) { - status = status + 2; + status = status + 2; } free(metabufr); From 46870fb121544dea6b81ed13d592d5d6f6091332 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 25 Nov 2024 02:44:23 +0100 Subject: [PATCH 2/2] frmts/hdf4/hdf-eos: disable lots of code unused by GDAL --- frmts/hdf4/hdf-eos/EHapi.c | 23 ++++--- frmts/hdf4/hdf-eos/GDapi.c | 107 +++++++++++++++++++++++---------- frmts/hdf4/hdf-eos/HdfEosDef.h | 69 ++++++++++++++++++--- frmts/hdf4/hdf-eos/SWapi.c | 104 ++++++++++++++++++++++---------- 4 files changed, 221 insertions(+), 82 deletions(-) diff --git a/frmts/hdf4/hdf-eos/EHapi.c b/frmts/hdf4/hdf-eos/EHapi.c index 3da68c6a9e75..8a6b6af3877d 100644 --- a/frmts/hdf4/hdf-eos/EHapi.c +++ b/frmts/hdf4/hdf-eos/EHapi.c @@ -46,7 +46,9 @@ static int32 *EHXsdTable = NULL; #define MAX_RETRIES 10 /* Function Prototypes */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) || defined(HDFEOS_SW_WRITE_SUPPORT) static intn EHmetalist(const char *, char *); +#endif static intn EHreset_maxopenfiles(intn); static intn EHget_maxopenfiles(intn *, intn *); static intn EHget_numfiles(void); @@ -580,7 +582,7 @@ EHidinfo(int32 fid, int32 * HDFfid, int32 * sdInterfaceID) } - +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -623,7 +625,7 @@ EHfilename(int32 fid, char *filename) return (status); } - +#endif @@ -1396,6 +1398,7 @@ EHrevflds(const char *dimlist, char *revdimlist) } +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -1511,10 +1514,11 @@ EHcntGROUP(char *metabuf[]) return (count); } +#endif - +#if defined(HDFEOS_GD_WRITE_SUPPORT) || defined(HDFEOS_SW_WRITE_SUPPORT) /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -1632,11 +1636,11 @@ EHmetalist(const char *instring, char *outstring) return (status); } +#endif - - +#if defined(HDFEOS_GD_WRITE_SUPPORT) || defined(HDFEOS_SW_WRITE_SUPPORT) /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -2391,6 +2395,7 @@ EHinsertmeta(int32 sdInterfaceID, const char *structname, const char *structcode return (status); } +#endif /*----------------------------------------------------------------------------| @@ -2681,7 +2686,7 @@ EHmetagroup(int32 sdInterfaceID, const char *structname, const char *structcode, - +#if defined(HDFEOS_GD_WRITE_SUPPORT) || defined(HDFEOS_SW_WRITE_SUPPORT) /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -2909,12 +2914,12 @@ EHfillfld(int32 sdid, int32 rank, CPL_UNUSED int32 truerank, int32 size, int32 o return (status); } +#endif - - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -3058,7 +3063,7 @@ EHbisect(float64(*func) (float64[]), float64 funcParms[], int32 nParms, return (status); } - +#endif diff --git a/frmts/hdf4/hdf-eos/GDapi.c b/frmts/hdf4/hdf-eos/GDapi.c index 6ff94e30836c..cc09d9379983 100644 --- a/frmts/hdf4/hdf-eos/GDapi.c +++ b/frmts/hdf4/hdf-eos/GDapi.c @@ -102,9 +102,11 @@ extern void inv_init(int32, int32, float64 *, int32, const char *, const char * #define GDIDOFFSET 4194304 #define SQUARE(x) ((x) * (x)) /* x**2 */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) static int32 GDXSDcomb[512*5]; -static char GDXSDname[HDFE_NAMBUFSIZE]; static char GDXSDdims[HDFE_DIMBUFSIZE]; +static char GDXSDname[HDFE_NAMBUFSIZE]; +#endif #define NGRID 200 @@ -231,16 +233,21 @@ static intn GDll2ij(int32, int32, float64 [], int32, int32, int32, float64[], float64[], float64[]); static intn GDgetdefaults(int32, int32, float64[], int32, float64[], float64[]); +#ifdef HDFEOS_GD_WRITE_SUPPORT static intn GDtangentpnts(int32, float64[], float64[], float64[], float64[], float64 [], int32 *); +#endif static intn GDwrrdtile(int32, const char *, const char *, int32 [], VOIDP); +#ifdef UNUSED_BY_GDAL static intn GDll2mm_cea(int32,int32, int32, float64[], int32, int32, float64[], float64[], int32, float64[],float64[], float64[], float64[], float64 *, float64 *); - +#endif +#ifdef HDFEOS_GD_WRITE_SUPPORT static intn GDmm2ll_cea(int32, int32, int32, float64[], int32, int32, float64[], float64[], int32, float64[], float64[], float64[], float64[]); +#endif /*----------------------------------------------------------------------------| | BEGIN_PROLOG | @@ -287,7 +294,7 @@ GDopen(const char *filename, intn l_access) } - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -550,7 +557,7 @@ GDcreate(int32 fid, const char *gridname, int32 xdimsize, int32 ydimsize, } return (gridID); } - +#endif /*----------------------------------------------------------------------------| @@ -909,7 +916,7 @@ GDchkgdid(int32 gridID, const char *routname, } - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -1558,7 +1565,7 @@ GDdefpixreg(int32 gridID, int32 pixregcode) return (status); } - +#endif @@ -2771,7 +2778,7 @@ GDfieldinfo(int32 gridID, const char *fieldname, int32 * rank, int32 dims[], - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -3571,7 +3578,7 @@ GDwritefieldmeta(int32 gridID, const char *fieldname, const char *dimlist, } return (status); } - +#endif @@ -4078,7 +4085,7 @@ GDwrrdfield(int32 gridID, const char *fieldname, const char *code, return (status); } - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -4122,7 +4129,7 @@ GDwritefield(int32 gridID, const char *fieldname, data); return (status); } - +#endif @@ -4241,7 +4248,7 @@ GDwrrdattr(int32 gridID, const char *attrname, int32 numbertype, int32 count, } - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -4285,7 +4292,7 @@ GDwriteattr(int32 gridID, const char *attrname, int32 numbertype, int32 count, return (status); } - +#endif /*----------------------------------------------------------------------------| @@ -5068,6 +5075,7 @@ GDinqgrid(const char *filename, char *gridlist, int32 * strbufsize) } +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -5153,7 +5161,7 @@ GDsetfillvalue(int32 gridID, const char *fieldname, VOIDP fillval) } return (status); } - +#endif @@ -5272,13 +5280,18 @@ GDdetach(int32 gridID) { intn i; /* Loop index */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) intn j; /* Loop index */ +#endif intn k; /* Loop index */ intn status = 0; /* routine return status variable */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) intn statusFill = 0; /* return status from GDgetfillvalue */ +#endif - int32 *namelen; /* Pointer to name string length array */ - int32 *dimlen; /* Pointer to dim string length array */ + int32 *namelen = NULL; /* Pointer to name string length array */ + int32 *dimlen = NULL; /* Pointer to dim string length array */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) int32 slen1[3]; /* String length array 1 */ int32 slen2[3]; /* String length array 2 */ int32 nflds; /* Number of fields */ @@ -5287,29 +5300,39 @@ GDdetach(int32 gridID) int32 sdid; /* SDS ID */ int32 vgid; /* Vgroup ID */ int32 dims[3]; /* Dimension array */ - int32 *offset; /* Pointer to merged field offset array */ - int32 *indvdims; /* Pointer to merged field size array */ +#endif + int32 *offset = NULL; /* Pointer to merged field offset array */ + int32 *indvdims = NULL; /* Pointer to merged field size array */ int32 sdInterfaceID; /* SDS interface ID */ int32 gID; /* Grid ID - offset */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) int32 nflds0; /* Number of fields */ - int32 *namelen0; /* Pointer to name string length array */ +#endif + int32 *namelen0 = NULL; /* Pointer to name string length array */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) int32 rank; /* Rank of merged field */ int32 truerank; /* True rank of merged field */ +#endif int32 idOffset = GDIDOFFSET; /* Grid ID offset */ int32 dum; /* Dummy variable */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) char *nambuf; /* Pointer to name buffer */ - char **nameptr; /* Pointer to name string pointer array */ - char **dimptr; /* Pointer to dim string pointer array */ - char **nameptr0; /* Pointer to name string pointer array */ +#endif + char **nameptr = NULL; /* Pointer to name string pointer array */ + char **dimptr = NULL; /* Pointer to dim string pointer array */ + char **nameptr0 = NULL; /* Pointer to name string pointer array */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) char *ptr1[3]; /* String pointer array */ char *ptr2[3]; /* String pointer array */ char dimbuf1[128]; /* Dimension buffer 1 */ char dimbuf2[128]; /* Dimension buffer 2 */ +#endif char gridname[VGNAMELENMAX + 1]; /* Grid name */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) char *utlbuf; /* Utility buffer */ char fillval[32];/* Fill value buffer */ - +#endif status = GDchkgdid(gridID, "GDdetach", &dum, &sdInterfaceID, &dum); @@ -5325,9 +5348,13 @@ GDdetach(int32 gridID) /* SDS combined fields */ /* ------------------- */ +#if defined(HDFEOS_GD_WRITE_SUPPORT) if (strlen(GDXSDname) == 0) +#endif { +#if defined(HDFEOS_GD_WRITE_SUPPORT) nflds = 0; +#endif /* Allocate "dummy" arrays so free() doesn't bomb later */ /* ---------------------------------------------------- */ @@ -5408,6 +5435,7 @@ GDdetach(int32 gridID) return(-1); } } +#if defined(HDFEOS_GD_WRITE_SUPPORT) else { /* @@ -5507,7 +5535,6 @@ GDdetach(int32 gridID) nflds = EHparsestr(GDXSDdims, ';', dimptr, dimlen); } - for (i = 0; i < nflds; i++) { if (GDXSDcomb[5 * i] != 0 && @@ -5764,7 +5791,7 @@ GDdetach(int32 gridID) strcat(GDXSDname, ","); strcat(GDXSDdims, ";"); } - +#endif /* Free up a bunch of dynamically allocated arrays */ @@ -6676,7 +6703,7 @@ GDll2ij(int32 projcode, int32 zonecode, float64 projparm[], - +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -6934,9 +6961,10 @@ GDrs2ll(int32 projcode, float64 projparm[], return (status); } +#endif - +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -7124,7 +7152,6 @@ homDyDtheta(float64 parms[]) - /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -8332,11 +8359,11 @@ GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[]) free(gridname); return (regionID); } +#endif - - +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -8966,6 +8993,7 @@ GDdupregion(int32 oldregionID) } return (newregionID); } +#endif /*----------------------------------------------------------------------------| @@ -9046,7 +9074,7 @@ for (j=0; j<8; j++) \ } \ - +#ifdef HDFEOS_GD_WRITE_SUPPORT int32 GDdefvrtregion(int32 gridID, int32 regionID, const char *vertObj, float64 range[]) { @@ -9374,7 +9402,7 @@ GDdeftimeperiod(int32 gridID, int32 periodID, float64 starttime, return (periodID); } - +#endif /*----------------------------------------------------------------------------| @@ -9844,6 +9872,7 @@ GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[], } +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -10271,6 +10300,8 @@ GDinterpolate(int32 gridID, int32 nValues, float64 lonVal[], float64 latVal[], } } +#endif + /*********************************************** GDwrrdtile -- This function is the underlying function below GDwritetile and @@ -10393,7 +10424,6 @@ GDwrrdtile(int32 gridID, const char *fieldname, const char *code, int32 start[], return (status); } - /*********************************************** GDtileinfo -- This function queries the field to determine if it is tiled. If it is @@ -10496,6 +10526,7 @@ Alexis Zubrow ********************************************************/ +#ifdef HDFEOS_GD_WRITE_SUPPORT intn GDwritetile(int32 gridID, const char *fieldname, int32 tilecoords[], VOIDP tileData) @@ -10507,6 +10538,8 @@ GDwritetile(int32 gridID, const char *fieldname, int32 tilecoords[], return (status); } +#endif + /*********************************************** GDreadtile -- This function reads one tile from a particular field. @@ -10528,6 +10561,8 @@ GDreadtile(int32 gridID, const char *fieldname, int32 tilecoords[], return (status); } + +#ifdef UNUSED_BY_GDAL /*********************************************** GDsettilecache -- This function sets the cache size for a tiled field. @@ -10600,7 +10635,10 @@ GDsettilecache(int32 gridID, const char *fieldname, int32 maxcache, CPL_UNUSED i return (status); } +#endif + +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -10753,7 +10791,9 @@ GDsettilecomp(int32 gridID, const char *fieldname, int32 tilerank, int32* } return (status); } +#endif +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -10884,8 +10924,10 @@ static intn GDll2mm_cea(int32 projcode,int32 zonecode, int32 spherecode, } return (0); } +#endif +#ifdef HDFEOS_GD_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -10975,6 +11017,7 @@ static intn GDmm2ll_cea(int32 projcode,int32 zonecode, int32 spherecode, } return(status); } +#endif /*----------------------------------------------------------------------------| | BEGIN_PROLOG | diff --git a/frmts/hdf4/hdf-eos/HdfEosDef.h b/frmts/hdf4/hdf-eos/HdfEosDef.h index 88f65dddbd2d..66fe1632d48b 100644 --- a/frmts/hdf4/hdf-eos/HdfEosDef.h +++ b/frmts/hdf4/hdf-eos/HdfEosDef.h @@ -10,9 +10,9 @@ /* Copyright (C) 1996 Hughes and Applied Research Corporation -Permission to use, modify, and distribute this software and its documentation -for any purpose without fee is hereby granted, provided that the above -copyright notice appear in all copies and that both that copyright notice and +Permission to use, modify, and distribute this software and its documentation +for any purpose without fee is hereby granted, provided that the above +copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. */ @@ -81,9 +81,9 @@ this permission notice appear in supporting documentation. /* Compression Modes */ #define HDFE_COMP_NONE 0 -#define HDFE_COMP_RLE 1 +#define HDFE_COMP_RLE 1 #define HDFE_COMP_NBIT 2 -#define HDFE_COMP_SKPHUFF 3 +#define HDFE_COMP_SKPHUFF 3 #define HDFE_COMP_DEFLATE 4 @@ -130,15 +130,20 @@ extern "C" { /* Swath Prototype */ int32 SWopen(const char *, intn); +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 SWcreate(int32, const char *); +#endif int32 SWattach(int32, const char *); +#ifdef HDFEOS_SW_WRITE_SUPPORT intn SWdefdim(int32, char *, int32); intn SWdefcomp(int32, int32, intn []); +#endif int32 SWdiminfo(int32, const char *); intn SWmapinfo(int32, const char *, const char *, int32 *, int32 *); int32 SWidxmapinfo(int32, const char *, const char *, int32 []); intn SWfieldinfo(int32, const char *, int32 *, int32 [], int32 *, char *); intn SWcompinfo(int32, const char *, int32 *, intn []); +#ifdef HDFEOS_SW_WRITE_SUPPORT intn SWdefdimmap(int32, const char *, const char *, int32, int32); intn SWdefidxmap(int32, const char *, const char *, int32 []); intn SWdefgeofield(int32, const char *, const char *, int32, int32); @@ -146,6 +151,7 @@ intn SWdefdatafield(int32, const char *, const char *, int32, int32); intn SWwritegeometa(int32, const char *, const char *, int32); intn SWwritedatameta(int32, const char *, const char *, int32); intn SWwriteattr(int32, const char *, int32, int32, VOIDP); +#endif intn SWreadattr(int32, const char *, VOIDP); intn SWattrinfo(int32, const char *, int32 *, int32 *); int32 SWinqdims(int32, char *, int32 []); @@ -156,31 +162,50 @@ int32 SWinqdatafields(int32, char *, int32 [],int32 []); int32 SWinqattrs(int32, char *, int32 *); int32 SWnentries(int32, int32, int32 *); int32 SWinqswath(const char *, char *, int32 *); +#ifdef HDFEOS_SW_WRITE_SUPPORT intn SWwritefield(int32, const char *, int32 [], int32 [], int32 [], VOIDP); +#endif intn SWreadfield(int32, const char *, int32 [], int32 [], int32 [], VOIDP); +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 SWdefboxregion(int32, float64 [], float64 [], int32); int32 SWdefscanregion(int32, const char *, float64 [], int32); +#endif +#ifdef UNUSED_BY_GDAL int32 SWregionindex(int32, float64 [], float64 [], int32, char *, int32 []); intn SWextractregion(int32, int32, const char *, int32, VOIDP); intn SWregioninfo(int32, int32, const char *, int32 *, int32 *, int32 [], int32 *); int32 SWdupregion(int32); +#endif +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 SWdeftimeperiod(int32, float64, float64, int32); +#endif +#ifdef UNUSED_BY_GDAL intn SWextractperiod(int32, int32, const char *, int32, VOIDP); intn SWperiodinfo(int32, int32, const char *, int32 *, int32 *, int32 [], int32 *); int32 SWdefvrtregion(int32, int32, const char *, float64 []); +#endif +#ifdef HDFEOS_SW_WRITE_SUPPORT intn SWsetfillvalue(int32, const char *, VOIDP); +#endif intn SWgetfillvalue(int32, const char *, VOIDP); intn SWdetach(int32); intn SWclose(int32); +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 SWupdateidxmap(int32, int32, int32 [], int32 [], int32 []); +#endif intn SWgeomapinfo(int32, const char *); +#ifdef HDFEOS_SW_WRITE_SUPPORT intn SWupdatescene(int32, int32); +#endif intn SWsdid(int32, const char *, int32 *); /* Grid Prototypes */ int32 GDopen(const char *, intn); +#ifdef HDFEOS_GD_WRITE_SUPPORT int32 GDcreate(int32, const char *, int32, int32, float64 [], float64 []); +#endif int32 GDattach(int32, const char *); +#ifdef HDFEOS_GD_WRITE_SUPPORT intn GDdefdim(int32, const char *, int32); intn GDdefproj(int32, int32, int32, int32, float64 []); intn GDblkSOMoffset(int32, float32 [], int32, const char *); @@ -189,6 +214,7 @@ intn GDdeftile(int32, int32, int32, int32 []); intn GDsettilecomp(int32, const char *, int32, int32 *, int32, intn *); intn GDdeforigin(int32, int32); intn GDdefpixreg(int32, int32); +#endif int32 GDdiminfo(int32, const char *); intn GDgridinfo(int32, int32 *, int32 *, float64 [], float64 []); intn GDprojinfo(int32, int32 *, int32 *, int32 *, float64 []); @@ -197,15 +223,23 @@ intn GDpixreginfo(int32, int32 *); intn GDcompinfo(int32, const char *, int32 *, intn []); intn GDfieldinfo(int32, const char *, int32 *, int32 [], int32 *, char *); intn GDtileinfo(int32, const char *, int32 *, int32 *, int32 []); +#ifdef UNUSED_BY_GDAL intn GDsettilecache(int32, const char *, int32, int32); +#endif +#ifdef HDFEOS_GD_WRITE_SUPPORT intn GDwritetile(int32, const char *, int32 [], VOIDP); +#endif intn GDreadtile(int32, const char *, int32 [], VOIDP); +#ifdef HDFEOS_GD_WRITE_SUPPORT intn GDdeffield(int32, const char *, const char *, int32, int32); intn GDwritefieldmeta(int32, const char *, const char *, int32); intn GDwritefield(int32, const char *, int32 [], int32 [], int32 [], VOIDP); +#endif intn GDreadfield(int32, const char *, int32 [], int32 [], int32 [], VOIDP); +#ifdef HDFEOS_GD_WRITE_SUPPORT intn GDwriteattr(int32, const char *, int32 , int32, VOIDP); +#endif intn GDreadattr(int32, const char *, VOIDP); intn GDattrinfo(int32, const char *, int32 *, int32 *); int32 GDinqdims(int32, char *, int32 []); @@ -213,26 +247,37 @@ int32 GDinqfields(int32, char *, int32 [], int32 []); int32 GDinqattrs(int32, char *, int32 *); int32 GDnentries(int32, int32, int32 *); int32 GDinqgrid(const char *, char *, int32 *); +#ifdef HDFEOS_GD_WRITE_SUPPORT int32 GDdefboxregion(int32, float64 [], float64 []); int32 GDdefvrtregion(int32, int32, const char *, float64 []); int32 GDdeftimeperiod(int32, int32, float64, float64); +#endif +#ifdef UNUSED_BY_GDAL intn GDextractregion(int32, int32, const char *, VOIDP); intn GDregioninfo(int32, int32, const char *, int32 *, int32 *, int32 [], int32 *, float64 [], float64 []); int32 GDdupregion(int32); +#endif intn GDgetpixels(int32, int32, float64 [], float64 [], int32 [], int32 []); int32 GDgetpixvalues(int32, int32, int32 [], int32 [], const char *, VOIDP); +#ifdef UNUSED_BY_GDAL int32 GDinterpolate(int32, int32, float64 [], float64 [], const char *, float64 []); +#endif +#ifdef HDFEOS_GD_WRITE_SUPPORT intn GDsetfillvalue(int32, const char *, VOIDP); +#endif intn GDgetfillvalue(int32, const char *, VOIDP); intn GDdetach(int32); intn GDclose(int32); +#ifdef UNUSED_BY_GDAL intn GDrs2ll(int32, float64 [], int32, int32, float64 [], float64 [], int32, float64 [], float64 [], float64 [], float64 [], int32, int32); +#endif intn GDsdid(int32, const char *, int32 *); +#ifdef UNUSED_BY_GDAL /* Point Prototypes */ int32 PTopen(const char *, intn); int32 PTcreate(int32, const char *); @@ -268,7 +313,7 @@ intn PTextractregion(int32, int32 regionID, int32, const char *, VOIDP); intn PTextractperiod(int32, int32 periodID, int32, const char *, VOIDP); intn PTdetach(int32); intn PTclose(int32); - +#endif /* EH Utility Prototypes */ @@ -284,21 +329,29 @@ intn EHchkfid(int32, const char *, int32 *, int32 *, uint8 *); intn EHidinfo(int32, int32 *, int32 *); int32 EHgetid(int32, int32, const char *, intn, const char *); intn EHrevflds(const char *, char *); +#if defined(HDFEOS_GD_WRITE_SUPPORT) || defined(HDFEOS_SW_WRITE_SUPPORT) intn EHinsertmeta(int32, const char *, const char *, int32, char *, int32 []); +#endif intn EHgetmetavalue(char *[], const char *, char *); char * EHmetagroup(int32, const char *, const char *, const char *, char *[]); +#if defined(HDFEOS_GD_WRITE_SUPPORT) || defined(HDFEOS_SW_WRITE_SUPPORT) intn EHfillfld(int32, int32, int32, int32, int32, int32 [], VOIDP); +#endif intn EHattr(int32, int32, const char *, int32, int32, const char *, VOIDP); intn EHattrinfo(int32, int32, const char *, int32 *, int32 *); int32 EHattrcat(int32, int32, char *, int32 *); +#ifdef UNUSED_BY_GDAL intn EHfilename(int32, char *); int32 EHcntOBJECT(char *[]); int32 EHcntGROUP(char *[]); -/* 9/3/97 Abe changed the first argument from +#endif +/* 9/3/97 Abe changed the first argument from float64 (float64 []) to float64 (*) (float64 []) for SunOS float64 () (float64 []) to float64 (*) (float64 []) for all other OSs */ -intn EHbisect(float64 (*) (float64 []), float64 [], int32, float64, float64, +#ifdef HDFEOS_GD_WRITE_SUPPORT +intn EHbisect(float64 (*) (float64 []), float64 [], int32, float64, float64, float64, float64 *); +#endif int32 EHinquire(const char *, const char *, char *, int32 *); intn EHclose(int32); diff --git a/frmts/hdf4/hdf-eos/SWapi.c b/frmts/hdf4/hdf-eos/SWapi.c index 4e51d32666bc..27c11e3340a9 100644 --- a/frmts/hdf4/hdf-eos/SWapi.c +++ b/frmts/hdf4/hdf-eos/SWapi.c @@ -88,15 +88,21 @@ June 05, 2003 Abe Taaheri / Bruce Beaumont static int32 SWX1dcomb[512*3]; +#ifdef HDFEOS_SW_WRITE_SUPPORT static int32 SWXSDcomb[512*5]; +#endif static char SWXSDname[HDFE_NAMBUFSIZE]; +#ifdef HDFEOS_SW_WRITE_SUPPORT static char SWXSDdims[HDFE_DIMBUFSIZE]; +#endif +#ifdef UNUSED_BY_GDAL /* This flag was added to allow the Time field to have different Dimensions ** than Longitude and Latitude and still be used for subsetting ** 23 June,1997 DaW */ static intn timeflag = 0; +#endif /* Added for routine that converts scanline to Lat/long @@ -158,7 +164,9 @@ static struct swathRegion *SWXRegion[NSWATHREGN]; static intn SWchkswid(int32, const char *, int32 *, int32 *, int32 *); static int32 SWfinfo(int32, const char *, const char *, int32 *, int32 [], int32 *, char *); +#ifdef HDFEOS_SW_WRITE_SUPPORT static intn SWdefinefield(int32, const char *, const char *, const char *, int32, int32); +#endif static intn SWwrrdattr(int32, const char *, int32, int32, const char *, VOIDP); static intn SW1dfldsrch(int32, int32, const char *, const char *, int32 *, int32 *, int32 *); @@ -167,9 +175,10 @@ static intn SWSDfldsrch(int32, int32, const char *, int32 *, int32 *, static intn SWwrrdfield(int32, const char *, const char *, int32 [], int32 [], int32 [], VOIDP); static int32 SWinqfields(int32, const char *, char *, int32 [], int32 []); +#ifdef UNUSED_BY_GDAL static intn SWscan2longlat(int32, const char *, VOIDP, int32 [], int32 [], int32 *, int32, int32); - +#endif /*----------------------------------------------------------------------------| | BEGIN_PROLOG | @@ -213,6 +222,7 @@ SWopen(const char *filename, intn i_access) return (fid); } +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -455,7 +465,7 @@ SWcreate(int32 fid, const char *swathname) } return (swathID); } - +#endif /*----------------------------------------------------------------------------| | BEGIN_PROLOG | @@ -874,7 +884,7 @@ SWchkswid(int32 swathID, const char *routname, - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -951,7 +961,7 @@ SWdefdim(int32 swathID, char *dimname, int32 dim) } return (status); } - +#endif /*----------------------------------------------------------------------------| @@ -1840,7 +1850,7 @@ SWfieldinfo(int32 swathID, const char *fieldname, int32 * rank, int32 dims[], - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -2842,7 +2852,6 @@ SWdefinefield(int32 swathID, const char *fieldtype, const char *fieldname, const - /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -3077,6 +3086,7 @@ SWwritedatameta(int32 swathID, const char *fieldname, const char *dimlist, } return (status); } +#endif @@ -3145,7 +3155,7 @@ SWwrrdattr(int32 swathID, const char *attrname, int32 numbertype, int32 count, } - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -3189,7 +3199,7 @@ SWwriteattr(int32 swathID, const char *attrname, int32 numbertype, int32 count, return (status); } - +#endif /*----------------------------------------------------------------------------| @@ -5262,7 +5272,7 @@ SWwrrdfield(int32 swathID, const char *fieldname, const char *code, } - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -5306,7 +5316,7 @@ SWwritefield(int32 swathID, const char *fieldname, data); return (status); } - +#endif @@ -5358,7 +5368,7 @@ SWreadfield(int32 swathID, const char *fieldname, - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -5988,10 +5998,11 @@ SWdefboxregion(int32 swathID, float64 cornerlon[], float64 cornerlat[], } } +#endif - +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -6631,9 +6642,9 @@ SWregionindex(int32 swathID, float64 cornerlon[], float64 cornerlat[], } } +#endif - - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -6928,7 +6939,9 @@ SWdeftimeperiod(int32 swathID, float64 starttime, float64 stoptime, return (periodID); } +#endif +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -7756,6 +7769,7 @@ SWextractregion(int32 swathID, int32 regionID, const char *fieldname, } + /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -8109,6 +8123,7 @@ int32 edge[], int32 *idxmap, int32 startscanline, int32 stopscanline) } + /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -8158,13 +8173,13 @@ SWextractperiod(int32 swathID, int32 periodID, const char *fieldname, if (status != 0) timeflag = 0; /*clear timeflag if SWextractregion failed*/ return (status); } +#endif - - +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -8231,8 +8246,10 @@ SWdupregion(int32 oldregionID) return (newregionID); } +#endif +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -8898,9 +8915,9 @@ SWregioninfo(int32 swathID, int32 regionID, const char *fieldname, return (status); } +#endif - - +#ifdef UNUSED_BY_GDAL /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -9518,9 +9535,10 @@ SWdefvrtregion(int32 swathID, int32 regionID, const char *vertObj, float64 range return (regionID); } +#endif - +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -9894,7 +9912,7 @@ SWsetfillvalue(int32 swathID, const char *fieldname, VOIDP fillval) } return (status); } - +#endif @@ -10002,16 +10020,21 @@ SWdetach(int32 swathID) { intn i; /* Loop index */ +#ifdef HDFEOS_SW_WRITE_SUPPORT intn j; /* Loop index */ +#endif intn k; /* Loop index */ intn status = 0; /* routine return status variable */ +#ifdef HDFEOS_SW_WRITE_SUPPORT intn statusFill = 0; /* return status from SWgetfillvalue */ +#endif uint8 *buf; /* Buffer for blank (initial) 1D records */ int32 vdataID; /* Vdata ID */ - int32 *namelen; /* Pointer to name string length array */ - int32 *dimlen; /* Pointer to dim string length array */ + int32 *namelen = NULL; /* Pointer to name string length array */ + int32 *dimlen = NULL; /* Pointer to dim string length array */ +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 slen1[3]; /* String length array 1 */ int32 slen2[3]; /* String length array 2 */ int32 nflds; /* Number of fields */ @@ -10019,29 +10042,38 @@ SWdetach(int32 swathID) int32 cmbfldcnt; /* Number of fields combined */ int32 sdid; /* SDS ID */ int32 vgid; /* Vgroup ID */ +#endif int32 dims[3]; /* Dimension array */ - int32 *offset; /* Pointer to merged field offset array */ - int32 *indvdims; /* Pointer to merged field size array */ + int32 *offset = NULL; /* Pointer to merged field offset array */ + int32 *indvdims = NULL; /* Pointer to merged field size array */ int32 sdInterfaceID; /* SDS interface ID */ int32 sID; /* Swath ID - offset */ +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 nflds0; /* Number of fields */ - int32 *namelen0; /* Pointer to name string length array */ +#endif + int32 *namelen0 = NULL; /* Pointer to name string length array */ +#ifdef HDFEOS_SW_WRITE_SUPPORT int32 rank; /* Rank of merged field */ int32 truerank; /* True rank of merged field */ +#endif int32 idOffset = SWIDOFFSET; /* Swath ID offset */ int32 dum; /* Dummy variable */ - char *nambuf; /* Pointer to name buffer */ - char **nameptr; /* Pointer to name string pointer array */ - char **dimptr; /* Pointer to dim string pointer array */ - char **nameptr0; /* Pointer to name string pointer array */ + char *nambuf = NULL; /* Pointer to name buffer */ + char **nameptr = NULL; /* Pointer to name string pointer array */ + char **dimptr = NULL; /* Pointer to dim string pointer array */ + char **nameptr0 = NULL; /* Pointer to name string pointer array */ +#ifdef HDFEOS_SW_WRITE_SUPPORT char *ptr1[3]; /* String pointer array */ char *ptr2[3]; /* String pointer array */ char dimbuf1[128]; /* Dimension buffer 1 */ char dimbuf2[128]; /* Dimension buffer 2 */ +#endif char swathname[VGNAMELENMAX + 1]; /* Swath name */ +#ifdef HDFEOS_SW_WRITE_SUPPORT char *utlbuf; /* Utility buffer */ char fillval[32];/* Fill value buffer */ +#endif /* Check for proper swath ID and get SD interface ID */ /* ------------------------------------------------- */ @@ -10117,7 +10149,9 @@ SWdetach(int32 swathID) /* ------------------- */ if (strlen(SWXSDname) == 0) { +#ifdef HDFEOS_SW_WRITE_SUPPORT nflds = 0; +#endif /* Allocate "dummy" arrays so free() doesn't bomb later */ /* ---------------------------------------------------- */ @@ -10198,6 +10232,7 @@ SWdetach(int32 swathID) return(-1); } } +#if defined(HDFEOS_SW_WRITE_SUPPORT) else { /* @@ -10299,7 +10334,6 @@ SWdetach(int32 swathID) nflds = EHparsestr(SWXSDdims, ';', dimptr, dimlen); } - /* Loop through all the fields */ /* --------------------------- */ for (i = 0; i < nflds; i++) @@ -10598,6 +10632,7 @@ SWdetach(int32 swathID) free(utlbuf); } } +#endif @@ -10616,7 +10651,7 @@ SWdetach(int32 swathID) i++; } - +#ifdef HDFEOS_SW_WRITE_SUPPORT /* "Contract" SDcomb array */ /* ----------------------- */ for (i = 0; i < nflds; i++) @@ -10658,7 +10693,7 @@ SWdetach(int32 swathID) strcat(SWXSDname, ","); strcat(SWXSDdims, ";"); } - +#endif /* Free up a bunch of dynamically allocated arrays */ @@ -10768,6 +10803,7 @@ SWclose(int32 fid) return (status); } +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -10928,7 +10964,9 @@ SWupdatescene(int32 swathID, int32 regionID) return(status); } +#endif +#ifdef HDFEOS_SW_WRITE_SUPPORT /*----------------------------------------------------------------------------| | BEGIN_PROLOG | | | @@ -11416,7 +11454,7 @@ SWupdateidxmap(int32 swathID, int32 regionID, int32 l_indexin[], int32 l_indexou } } - +#endif /*----------------------------------------------------------------------------|