Skip to content

Commit

Permalink
degrib: fix cppcheck nullPointerOutOfMemory
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Dec 16, 2024
1 parent 8bea7c7 commit 378cda2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frmts/grib/degrib/degrib/degrib1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,11 @@ int GRIB1_RefTime (VSILFILE *fp, uInt4 gribLen, double *refTime)
return -1;
}
pds = (uChar *) malloc (sectLen * sizeof (uChar));
if(!pds)
{
errSprintf("Out of memory");
return -1;
}
*pds = *temp;
pds[1] = temp[1];
pds[2] = temp[2];
Expand Down
8 changes: 8 additions & 0 deletions frmts/grib/degrib/degrib/metaparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ static int ParseSect2_Wx (float *rdat, sInt4 nrdat, sInt4 *idat,

buffLen = 0;
buffer = (char *) malloc ((nidat + 1) * sizeof (char));
if( !buffer ) {
errSprintf ("Out of memory\n");
return -1;
}
while (groupLen > 0) {
for (j = 0; j < groupLen; j++) {
buffer[buffLen] = (char) idat[loc];
Expand Down Expand Up @@ -600,6 +604,10 @@ static int ParseSect2_Hazard (float *rdat, sInt4 nrdat, sInt4 *idat,

buffLen = 0;
buffer = (char *) malloc ((nidat + 1) * sizeof (char));
if (!buffer) {
errSprintf ("Out of memory\n");
return -1;
}
while (groupLen > 0) {
for (j = 0; j < groupLen; j++) {
buffer[buffLen] = (char) idat[loc];
Expand Down

0 comments on commit 378cda2

Please sign in to comment.