star-cad

Geometric operators for computer-aided design
git clone git://git.meso-star.fr/star-cad.git
Log | Files | Refs | README | LICENSE

commit 9e4d9c638aef45be83743a43153ab6b4a4bdb66f
parent 9e88050cf99ec5531542f7f3f8bcf85109434d09
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri,  9 Sep 2022 10:12:53 +0200

Fix non-detection of failed malloc

Diffstat:
Msrc/scad_geometry.c | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/scad_geometry.c b/src/scad_geometry.c @@ -429,12 +429,20 @@ scad_add_polygon ERR(check_device(FUNC_NAME)); points = malloc(count * sizeof(int)); + if(!points) { + res = RES_MEM_ERR; + goto error; + } for (i=0; i<count; ++i) { points[i] = gmshModelOccAddPoint(x[i], y[i], z, -1, -1, &ierr); ERR(gmsh_err_to_res_T(ierr)); } lines = malloc(count * sizeof(int)); + if(!lines) { + res = RES_MEM_ERR; + goto error; + } for (i=0; i<count-1; ++i) { lines[i] = gmshModelOccAddLine(points[i], points[i+1], -1, &ierr); ERR(gmsh_err_to_res_T(ierr)); @@ -945,6 +953,10 @@ scad_geometry_extrude if (tagout[2*i] == 3) extrude_sz += 2; } extrude_data = malloc(extrude_sz * sizeof(int)); + if(!extrude_data) { + res = RES_MEM_ERR; + goto error; + } j = 0; for (i=0; i<tagoutn/2; ++i) { if (tagout[2*i] == 3) { @@ -1203,6 +1215,10 @@ scad_step_import ERR(scad_geometry_create(str_cget(&strname), geom_array+i)); geom_array[i]->gmsh_dimTags_n = 2; geom_array[i]->gmsh_dimTags = malloc(2 * sizeof(int)); + if(!geom_array[i]->gmsh_dimTags) { + res = RES_MEM_ERR; + goto error; + } geom_array[i]->gmsh_dimTags[0] = tagout[2*i]; geom_array[i]->gmsh_dimTags[1] = tagout[2*i+1]; ERR(device_register_tags(geom_array[i]));