Commit 8c365094 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix implicit conversions in gribapiScanTimestep* routines.

parent 97b743e7
...@@ -847,7 +847,7 @@ void gribapiGetString(grib_handle *gh, const char *key, char *string, size_t len ...@@ -847,7 +847,7 @@ void gribapiGetString(grib_handle *gh, const char *key, char *string, size_t len
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
static static
void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
long recsize, off_t position, int datatype, int comptype, size_t len, const char *varname, size_t recsize, off_t position, int datatype, int comptype, size_t len, const char *varname,
int leveltype, int lbounds, int level1, int level2, int level_sf, int level_unit) int leveltype, int lbounds, int level1, int level2, int level_sf, int level_unit)
{ {
long editionNumber; long editionNumber;
...@@ -904,13 +904,14 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -904,13 +904,14 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
double *vctptr; double *vctptr;
GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0); GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0);
vctsize = lpar; /* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */
vctsize = (int)lpar;
if ( vctsize > 0 ) if ( vctsize > 0 )
{ {
vctptr = (double *) malloc(vctsize*sizeof(double)); vctptr = (double *) malloc(vctsize*sizeof(double));
dummy = vctsize; dummy = (size_t)vctsize;
GRIB_CHECK(grib_get_double_array(gh, "pv", vctptr, &dummy), 0); GRIB_CHECK(grib_get_double_array(gh, "pv", vctptr, &dummy), 0);
varDefVCT(vctsize, vctptr); varDefVCT((size_t)vctsize, vctptr);
free(vctptr); free(vctptr);
} }
break; break;
...@@ -966,8 +967,8 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -966,8 +967,8 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
datatype, &varID, &levelID, tsteptype, numavg, leveltype, datatype, &varID, &levelID, tsteptype, numavg, leveltype,
varname, stdname, longname, units); varname, stdname, longname, units);
(*record).varID = varID; (*record).varID = (short)varID;
(*record).levelID = levelID; (*record).levelID = (short)levelID;
varDefCompType(varID, comptype); varDefCompType(varID, comptype);
...@@ -1036,9 +1037,10 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -1036,9 +1037,10 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
status = grib_get_long(gh, "generatingProcessIdentifier", &processID); status = grib_get_long(gh, "generatingProcessIdentifier", &processID);
if ( status == 0 ) if ( status == 0 )
{ {
modelID = modelInq(varInqInst(varID), processID, NULL); /* FIXME: assert(processID >= INT_MIN && processID <= INT_MAX) */
modelID = modelInq(varInqInst(varID), (int)processID, NULL);
if ( modelID == CDI_UNDEFID ) if ( modelID == CDI_UNDEFID )
modelID = modelDef(varInqInst(varID), processID, NULL); modelID = modelDef(varInqInst(varID), (int)processID, NULL);
varDefModel(varID, modelID); varDefModel(varID, modelID);
} }
} }
...@@ -1139,7 +1141,7 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1139,7 +1141,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
off_t recpos = 0; off_t recpos = 0;
unsigned char *gribbuffer = NULL; unsigned char *gribbuffer = NULL;
long buffersize = 0; size_t buffersize = 0;
int rstatus; int rstatus;
int status; int status;
int fileID; int fileID;
...@@ -1154,7 +1156,7 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1154,7 +1156,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
int nrecords, nrecs, recID; int nrecords, nrecs, recID;
int nrecs_scanned = 0; int nrecs_scanned = 0;
int datatype; int datatype;
long recsize = 0; size_t recsize = 0;
int warn_time = TRUE; int warn_time = TRUE;
// int warn_numavg = TRUE; // int warn_numavg = TRUE;
int taxisID = -1; int taxisID = -1;
...@@ -1192,7 +1194,7 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1192,7 +1194,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
{ {
level1 = 0; level1 = 0;
level2 = 0; level2 = 0;
recsize = gribGetSize(fileID); recsize = (size_t)gribGetSize(fileID);
recpos = fileGetPos(fileID); recpos = fileGetPos(fileID);
if ( recsize == 0 ) if ( recsize == 0 )
...@@ -1213,13 +1215,13 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1213,13 +1215,13 @@ int gribapiScanTimestep1(stream_t * streamptr)
lieee = FALSE; lieee = FALSE;
comptype = COMPRESS_NONE; comptype = COMPRESS_NONE;
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 ) if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
{ {
comptype = COMPRESS_SZIP; comptype = COMPRESS_SZIP;
unzipsize += 100; unzipsize += 100;
if ( (long) buffersize < unzipsize ) if ( buffersize < (size_t)unzipsize )
{ {
buffersize = unzipsize; buffersize = (size_t)unzipsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize); gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
} }
} }
...@@ -1396,8 +1398,8 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1396,8 +1398,8 @@ int gribapiScanTimestep1(stream_t * streamptr)
taxis->type = TAXIS_ABSOLUTE; taxis->type = TAXIS_ABSOLUTE;
} }
taxis->vdate = datetime0.date; taxis->vdate = (int)datetime0.date;
taxis->vtime = datetime0.time; taxis->vtime = (int)datetime0.time;
vlistID = streamptr->vlistID; vlistID = streamptr->vlistID;
vlistDefTaxis(vlistID, taxisID); vlistDefTaxis(vlistID, taxisID);
...@@ -1453,7 +1455,7 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1453,7 +1455,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
off_t recpos = 0; off_t recpos = 0;
unsigned char *gribbuffer = NULL; unsigned char *gribbuffer = NULL;
long buffersize = 0; size_t buffersize = 0;
int fileID; int fileID;
int rtabnum = 0; int rtabnum = 0;
int rcode = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0; int rcode = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0;
...@@ -1464,7 +1466,7 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1464,7 +1466,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
size_t readsize; size_t readsize;
int nrecords, nrecs, recID, rindex; int nrecords, nrecs, recID, rindex;
int nrecs_scanned = 0; int nrecs_scanned = 0;
long recsize = 0; size_t recsize = 0;
// int warn_numavg = TRUE; // int warn_numavg = TRUE;
int tsteptype; int tsteptype;
int taxisID = -1; int taxisID = -1;
...@@ -1520,7 +1522,7 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1520,7 +1522,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
{ {
if ( rindex > nrecords ) break; if ( rindex > nrecords ) break;
recsize = gribGetSize(fileID); recsize = (size_t)gribGetSize(fileID);
recpos = fileGetPos(fileID); recpos = fileGetPos(fileID);
if ( recsize == 0 ) if ( recsize == 0 )
{ {
...@@ -1530,19 +1532,19 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1530,19 +1532,19 @@ int gribapiScanTimestep2(stream_t * streamptr)
if ( recsize > buffersize ) if ( recsize > buffersize )
{ {
buffersize = recsize; buffersize = recsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, (size_t)buffersize); gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
} }
readsize = recsize; readsize = recsize;
rstatus = gribRead(fileID, gribbuffer, &readsize); rstatus = gribRead(fileID, gribbuffer, &readsize);
if ( rstatus ) break; if ( rstatus ) break;
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 ) if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
{ {
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */ unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
if ( (long) buffersize < unzipsize ) if ( buffersize < (size_t)unzipsize )
{ {
buffersize = unzipsize; buffersize = (size_t)unzipsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize); gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
} }
} }
...@@ -1721,10 +1723,10 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1721,10 +1723,10 @@ int gribapiScanTimestep(stream_t * streamptr)
{ {
int rstatus = 0; int rstatus = 0;
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
long recsize = 0; size_t recsize = 0;
off_t recpos = 0; off_t recpos = 0;
unsigned char *gribbuffer; unsigned char *gribbuffer;
long buffersize = 0; size_t buffersize = 0;
int fileID; int fileID;
int rtabnum = 0; int rtabnum = 0;
int rcode = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0; int rcode = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0;
...@@ -1787,7 +1789,7 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1787,7 +1789,7 @@ int gribapiScanTimestep(stream_t * streamptr)
{ {
if ( rindex > nrecs ) break; if ( rindex > nrecs ) break;
recsize = gribGetSize(fileID); recsize = (size_t)gribGetSize(fileID);
recpos = fileGetPos(fileID); recpos = fileGetPos(fileID);
if ( recsize == 0 ) if ( recsize == 0 )
{ {
...@@ -1812,12 +1814,12 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1812,12 +1814,12 @@ int gribapiScanTimestep(stream_t * streamptr)
break; break;
} }
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 ) if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
{ {
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */ unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
if ( (long) buffersize < unzipsize ) if ( buffersize < (size_t)unzipsize )
{ {
buffersize = unzipsize; buffersize = (size_t)unzipsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize); gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
} }
} }
...@@ -1996,7 +1998,7 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1996,7 +1998,7 @@ int gribapiScanTimestep(stream_t * streamptr)
streamptr->ntsteps = tsID; streamptr->ntsteps = tsID;
} }
rstatus = streamptr->ntsteps; rstatus = (int)streamptr->ntsteps;
#else #else
Error("GRIB_API support not compiled in!"); Error("GRIB_API support not compiled in!");
#endif #endif
...@@ -2033,7 +2035,7 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri ...@@ -2033,7 +2035,7 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
} }
} }
recsize = gribsize; recsize = (size_t)gribsize;
gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize); gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize);
GRIB_CHECK(my_grib_set_double(gh, "missingValue", missval), 0); GRIB_CHECK(my_grib_set_double(gh, "missingValue", missval), 0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment