Skip to content

Commit

Permalink
croak if allocation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Aug 17, 2024
1 parent a9d4c26 commit ce55379
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion plplot.pd
Original file line number Diff line number Diff line change
Expand Up @@ -3796,6 +3796,7 @@ pp_def ('plsurf3d',
size_x = $SIZE(nx);
size_y = $SIZE(ny);
plAlloc2dGrid (&zz, size_x, size_y);
if (!zz) $CROAK("Failed to allocate memory for grid");
for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
zz[i][j] = $z(nx => i, ny => j);
Expand All @@ -3815,6 +3816,7 @@ pp_def('plsurf3dl',
size_x = $SIZE(nx);
size_y = $SIZE(ny);
plAlloc2dGrid (&zz, size_x, size_y);
if (!zz) $CROAK("Failed to allocate memory for grid");
for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
zz[i][j] = $z(nx => i, ny => j);
Expand Down Expand Up @@ -3922,7 +3924,16 @@ pp_def ('plAlloc2dGrid',
PLcGrid2 *grid = (PLcGrid2*) malloc(sizeof(PLcGrid2));
if (!grid) $CROAK("Failed to allocate memory for grid");
plAlloc2dGrid(&(grid->xg), nx, ny);
if (!grid->xg) {
free(grid);
$CROAK("Failed to allocate memory for grid");
}
plAlloc2dGrid(&(grid->yg), nx, ny);
if (!grid->yg) {
free(grid);
plFree2dGrid(grid->xg, nx, ny);
$CROAK("Failed to allocate memory for grid");
}
for (i = 0; i < nx; i++)
for (j = 0; j < ny; j++) {
grid->xg[i][j] = $xg(nx => i, ny => j);
Expand Down Expand Up @@ -4058,6 +4069,7 @@ pp_def ('plshades',
PLFLT **z;

plAlloc2dGrid (&z, nx, ny);
if (!z) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < nx; i++)
for (j = 0; j < ny; j++)
Expand Down Expand Up @@ -4094,6 +4106,7 @@ pp_def ('plcont',
size_y = $SIZE(ny);

plAlloc2dGrid (&ff, size_x, size_y);
if (!ff) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand Down Expand Up @@ -4124,6 +4137,7 @@ pp_def ('plmesh',
size_y = $SIZE(ny);

plAlloc2dGrid (&zz, size_x, size_y);
if (!zz) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand All @@ -4147,6 +4161,7 @@ pp_def ('plmeshc',
size_y = $SIZE(ny);

plAlloc2dGrid (&zz, size_x, size_y);
if (!zz) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand All @@ -4171,6 +4186,7 @@ pp_def ('plot3d',
size_y = $SIZE(ny);

plAlloc2dGrid (&zz, size_x, size_y);
if (!zz) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand All @@ -4194,6 +4210,7 @@ pp_def ('plot3dc',
size_y = $SIZE(ny);

plAlloc2dGrid (&zz, size_x, size_y);
if (!zz) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand Down Expand Up @@ -4242,7 +4259,7 @@ pp_def ('plshade1',
size_y = $SIZE(ny);

plAlloc2dGrid (&a, size_x, size_y);
if(a == NULL) $CROAK("Failed to allocate memory in plshade1_pp");
if (!a) $CROAK("Failed to allocate memory");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand Down Expand Up @@ -4275,6 +4292,7 @@ pp_def ('plimage',
size_y = $SIZE(ny);

plAlloc2dGrid (&idata, size_x, size_y);
if (!idata) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand Down Expand Up @@ -4312,6 +4330,7 @@ pp_def ('plimagefr',
PLPTR_RECEIVE_SV($COMP(pltr_data));

plAlloc2dGrid (&idata, size_x, size_y);
if (!idata) $CROAK("Failed to allocate memory for grid");

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++)
Expand Down Expand Up @@ -4607,6 +4626,7 @@ pp_def ('plgriddata',
size_y = $SIZE(nptsy);

plAlloc2dGrid (&zg, size_x, size_y);
if (!zg) $CROAK("Failed to allocate memory for grid");

c_plgriddata ($P(x), $P(y), $P(z), $SIZE(npts),
$P(xg), size_x, $P(yg), size_y,
Expand Down Expand Up @@ -5150,7 +5170,12 @@ pp_def ('plvect',
size_y = $SIZE(ny);

plAlloc2dGrid (&u, size_x, size_y);
if (!u) $CROAK("Failed to allocate memory for grid");
plAlloc2dGrid (&v, size_x, size_y);
if (!v) {
plFree2dGrid (u, size_x, size_y);
$CROAK("Failed to allocate memory for grid");
}

for (i = 0; i < size_x; i++)
for (j = 0; j < size_y; j++) {
Expand Down

0 comments on commit ce55379

Please sign in to comment.