Commit 34fee212 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Check return value of section2Length and grib2LocalSectionNumber.

parent 6b282eae
......@@ -459,40 +459,43 @@ void gribapiGetKeys(grib_handle *gh, int varID)
}
long section2Length;
grib_get_long(gh, "section2Length", &section2Length);
if ( section2Length > 0 )
int status = grib_get_long(gh, "section2Length", &section2Length);
if (status == 0 && section2Length > 0)
{
long grib2LocalSectionNumber;
long mpimType, mpimClass, mpimUser;
grib_get_long(gh, "grib2LocalSectionNumber", &grib2LocalSectionNumber);
size_t section2PaddingLength = 0;
int status = grib_get_size(gh, "section2Padding", &section2PaddingLength);
if ( status == 0 && section2PaddingLength > 0 )
status = grib_get_long(gh, "grib2LocalSectionNumber", &grib2LocalSectionNumber);
if (status == 0)
{
varDefKeyInt(varID, CDI_KEY_GRIB2LOCALSECTIONNUMBER, (int) grib2LocalSectionNumber);
varDefKeyInt(varID, CDI_KEY_SECTION2PADDINGLENGTH, (int) section2PaddingLength);
unsigned char *section2Padding = (unsigned char*) Malloc(section2PaddingLength);
grib_get_bytes(gh, "section2Padding", section2Padding, &section2PaddingLength);
varDefKeyBytes(varID, CDI_KEY_SECTION2PADDING, section2Padding, (int)section2PaddingLength);
Free(section2Padding);
size_t section2PaddingLength = 0;
status = grib_get_size(gh, "section2Padding", &section2PaddingLength);
if (status == 0 && section2PaddingLength > 0)
{
varDefKeyInt(varID, CDI_KEY_GRIB2LOCALSECTIONNUMBER, (int) grib2LocalSectionNumber);
varDefKeyInt(varID, CDI_KEY_SECTION2PADDINGLENGTH, (int) section2PaddingLength);
unsigned char *section2Padding = (unsigned char*) Malloc(section2PaddingLength);
grib_get_bytes(gh, "section2Padding", section2Padding, &section2PaddingLength);
varDefKeyBytes(varID, CDI_KEY_SECTION2PADDING, section2Padding, (int)section2PaddingLength);
Free(section2Padding);
}
else if ( grib_get_long(gh, "mpimType", &mpimType) == 0 &&
grib_get_long(gh, "mpimClass", &mpimClass) == 0 &&
grib_get_long(gh, "mpimUser", &mpimUser) == 0)
{
varDefKeyInt(varID, CDI_KEY_MPIMTYPE, mpimType);
varDefKeyInt(varID, CDI_KEY_MPIMCLASS, mpimClass);
varDefKeyInt(varID, CDI_KEY_MPIMUSER, mpimUser);
size_t revNumLen = 20;
unsigned char revNumber[revNumLen];
if ( grib_get_bytes(gh, "revNumber", revNumber, &revNumLen) == 0 )
varDefKeyBytes(varID, CDI_KEY_REVNUMBER, revNumber, (int)revNumLen);
long revStatus;
grib_get_long(gh, "revStatus", &revStatus);
varDefKeyInt(varID, CDI_KEY_REVSTATUS, revStatus);
}
}
else if ( grib_get_long(gh, "mpimType", &mpimType) == 0 &&
grib_get_long(gh, "mpimClass", &mpimClass) == 0 &&
grib_get_long(gh, "mpimUser", &mpimUser) == 0)
{
varDefKeyInt(varID, CDI_KEY_MPIMTYPE, mpimType);
varDefKeyInt(varID, CDI_KEY_MPIMCLASS, mpimClass);
varDefKeyInt(varID, CDI_KEY_MPIMUSER, mpimUser);
size_t revNumLen = 20;
unsigned char revNumber[revNumLen];
if ( grib_get_bytes(gh, "revNumber", revNumber, &revNumLen) == 0 )
varDefKeyBytes(varID, CDI_KEY_REVNUMBER, revNumber, (int)revNumLen);
long revStatus;
grib_get_long(gh, "revStatus", &revStatus);
varDefKeyInt(varID, CDI_KEY_REVSTATUS, revStatus);
}
}
}
......
Markdown is supported
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