commit 06c9abb4aa3d6d2a0533ade056ec403144579b16
parent 8f605f525e20c791cea7433a7022625b1c8e7d98
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 29 Nov 2022 16:16:46 +0100
BugFix: use of garbage pointer on error path
Diffstat:
1 file changed, 57 insertions(+), 57 deletions(-)
diff --git a/src/cg_building_model1.c b/src/cg_building_model1.c
@@ -61,7 +61,7 @@ build_floor
double e_insulation = data->ext_insulation;
double e_floor = data->floor;
double offset = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
double d[3] = {0, 0, 0};
@@ -72,7 +72,7 @@ build_floor
if (!prefix || !pg || !data || !floor) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -99,7 +99,7 @@ exit:
error:
goto exit;
}
-
+
static res_T
build_wall
(const char* prefix,
@@ -113,8 +113,8 @@ build_wall
double e_insulation = data->ext_insulation;
double depth = data->foundation;
double offset = 0;
- struct scpr_polygon* pg_int;
- struct scpr_polygon* pg_ext;
+ struct scpr_polygon* pg_int = NULL;
+ struct scpr_polygon* pg_ext = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
struct scad_geometry* footprint_int = NULL;
@@ -127,7 +127,7 @@ build_wall
if (!prefix || !pg || !data || !wall) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -154,8 +154,8 @@ build_wall
ERR(scad_cut_geometries(
NULL, &footprint_ext, 1, &footprint_int, 1, &footprint));
-
- d[2] = depth + height;
+
+ d[2] = depth + height;
ERR(scad_geometry_extrude(footprint, wallname, d, wall));
exit:
@@ -187,8 +187,8 @@ build_int_insulation
double e_ext_insulation = data->ext_insulation;
double e_int_insulation = data->int_insulation;
double offset = 0;
- struct scpr_polygon* pg_int;
- struct scpr_polygon* pg_ext;
+ struct scpr_polygon* pg_int = NULL;
+ struct scpr_polygon* pg_ext = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
struct scad_geometry* footprint_int = NULL;
@@ -202,7 +202,7 @@ build_int_insulation
if (!prefix || !pg || !data || !insulation) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -229,17 +229,17 @@ build_int_insulation
ERR(scad_cut_geometries(
NULL, &footprint_ext, 1, &footprint_int, 1, &footprint));
-
- d[2] = height - e_roof - attic - e_roof_insulation;
+
+ d[2] = height - e_roof - attic - e_roof_insulation;
ERR(scad_geometry_extrude(footprint, NULL, d, &geom));
-
+
if (inter_floor) {
ERR(scad_cut_geometries(
insulationname, &geom, 1, &inter_floor, 1, insulation));
} else {
ERR(scad_geometry_copy(geom, insulationname, insulation));
}
-
+
exit:
scad_geometry_delete(footprint);
@@ -253,7 +253,7 @@ exit:
error:
goto exit;
}
-
+
static res_T
build_roof
(const char* prefix,
@@ -268,7 +268,7 @@ build_roof
double e_roof = data->roof;
double offset = 0;
double z_roof = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
double d[3] = {0, 0, 0};
@@ -279,7 +279,7 @@ build_roof
if (!prefix || !pg || !data || !roof) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -324,7 +324,7 @@ build_roof_insulation
double e_roof_insulation = data->roof_insulation;
double offset = 0;
double z_insulation = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
double d[3] = {0, 0, 0};
@@ -335,7 +335,7 @@ build_roof_insulation
if (!prefix || !pg || !data || !insulation) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -379,7 +379,7 @@ build_floor_insulation
double e_floor_insulation = data->floor_insulation;
double offset = 0;
double z_insulation = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
double d[3] = {0, 0, 0};
@@ -390,7 +390,7 @@ build_floor_insulation
if (!prefix || !pg || !data || !insulation) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -439,7 +439,7 @@ build_inter_floor
double offset = 0;
double z_floor = 0;
double h_cavity = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry** floor_list = NULL;
double d[3] = {0, 0, 0};
@@ -450,7 +450,7 @@ build_inter_floor
if (!prefix || !pg || !data || !inter_floor) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -480,7 +480,7 @@ build_inter_floor
ERR(scad_fuse_geometries(
floorname,
- floor_list, sa_size(floor_list),
+ floor_list, sa_size(floor_list),
floor_list, sa_size(floor_list),
inter_floor));
@@ -491,7 +491,7 @@ exit:
for (i=0; i< floor_n; ++i) {
scad_geometry_delete(floor_list[i]);
}
- sa_release(floor_list);
+ sa_release(floor_list);
}
return res;
error:
@@ -508,8 +508,8 @@ build_ext_insulation
res_T res = RES_OK;
double e_insulation = data->ext_insulation;
double offset = 0;
- struct scpr_polygon* pg_int;
- struct scpr_polygon* pg_ext;
+ struct scpr_polygon* pg_int = NULL;
+ struct scpr_polygon* pg_ext = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
struct scad_geometry* footprint_int = NULL;
@@ -522,7 +522,7 @@ build_ext_insulation
if (!prefix || !pg || !data || !insulation) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -546,8 +546,8 @@ build_ext_insulation
ERR(scad_cut_geometries(
NULL, &footprint_ext, 1, &footprint_int, 1, &footprint));
-
- d[2] = height;
+
+ d[2] = height;
ERR(scad_geometry_extrude(footprint, insulationname, d, insulation));
exit:
@@ -577,7 +577,7 @@ build_crawlspace
double e_floor_insulation = data->floor_insulation;
double offset = 0;
double z_crawl= 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
double d[3] = {0, 0, 0};
@@ -588,7 +588,7 @@ build_crawlspace
if (!prefix || !pg || !data || !crawlspace) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -635,7 +635,7 @@ build_habitable
double e_roof_insulation = data->roof_insulation;
double e_attic = data->attic;
double offset = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
struct scad_geometry* geom = NULL;
@@ -647,7 +647,7 @@ build_habitable
if (!prefix || !pg || !data || !cavity) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -698,7 +698,7 @@ build_attic
double e_attic = data->attic;
double offset = 0;
double z_attic = 0;
- struct scpr_polygon* pg_int;
+ struct scpr_polygon* pg_int = NULL;
size_t nverts = 0;
struct scad_geometry* footprint = NULL;
double d[3] = {0, 0, 0};
@@ -709,7 +709,7 @@ build_attic
if (!prefix || !pg || !data || !attic) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -757,11 +757,11 @@ build_boundary
if (!prefix || !data_cad || !boundary) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
-
+
sa_push(list, data_cad->wall);
sa_push(list, data_cad->roof);
sa_push(list, data_cad->floor);
@@ -774,29 +774,29 @@ build_boundary
if (data_cad->attic_cavity) sa_push(list, data_cad->attic_cavity);
if (data_cad->crawlspace_cavity) sa_push(list, data_cad->crawlspace_cavity);
- ERR(scad_geometry_boundary(NULL, list, sa_size(list), &geom1));
-
- ERR(scad_geometry_boundary(NULL, &data_cad->external_insulation, 1, &geom2));
+ ERR(scad_geometry_boundary(NULL, list, sa_size(list), &geom1));
+
+ ERR(scad_geometry_boundary(NULL, &data_cad->external_insulation, 1, &geom2));
ERR(str_set(&name, prefix));
ERR(str_append(&name, "_boundary_ext_insulation"));
boundaryname = str_get(&name);
ERR(scad_intersect_geometries(boundaryname, &geom1, 1, &geom2, 1, &bound));
sa_push(*boundary, bound);
- ERR(scad_geometry_boundary(NULL, &data_cad->wall, 1, &geom2));
+ ERR(scad_geometry_boundary(NULL, &data_cad->wall, 1, &geom2));
ERR(str_set(&name, prefix));
ERR(str_append(&name, "_boundary_wall"));
boundaryname = str_get(&name);
ERR(scad_intersect_geometries(boundaryname, &geom1, 1, &geom2, 1, &bound));
sa_push(*boundary, bound);
- ERR(scad_geometry_boundary(NULL, &data_cad->roof, 1, &geom2));
+ ERR(scad_geometry_boundary(NULL, &data_cad->roof, 1, &geom2));
ERR(str_set(&name, prefix));
ERR(str_append(&name, "_boundary_roof"));
boundaryname = str_get(&name);
ERR(scad_intersect_geometries(boundaryname, &geom1, 1, &geom2, 1, &bound));
sa_push(*boundary, bound);
-
+
exit:
if (is_init) str_release(&name);
if (list) sa_release(list);
@@ -815,7 +815,7 @@ build_connection
{
res_T res = RES_OK;
struct scad_geometry* connect = NULL;
- size_t count = 0;
+ size_t count = 0;
char* cname = NULL;
struct str name;
int is_init = 0;
@@ -823,7 +823,7 @@ build_connection
if (!prefix || !data_cad || !connection) {
res = RES_BAD_ARG;
goto error;
- }
+ }
str_init(NULL, &name);
is_init = 1;
@@ -866,7 +866,7 @@ build_connection
/* with intermediate floor */
if (data_cad->intermediate_floor) {
CREATE_CONNECT(habitable_cavity,intermediate_floor,"_C_cavity_intermediate_floor");
- }
+ }
/* -------------------------------------------------------------------------*/
/* crawlspace cavity connections */
@@ -878,11 +878,11 @@ build_connection
CREATE_CONNECT(crawlspace_cavity, floor_insulation,"_C_crawlspace_insulation");
} else {
/* with floor */
- CREATE_CONNECT(crawlspace_cavity, floor,"_C_crawlspace_floor");
+ CREATE_CONNECT(crawlspace_cavity, floor,"_C_crawlspace_floor");
}
/* with wall */
- CREATE_CONNECT(crawlspace_cavity, wall,"_C_crawlspace_wall");
+ CREATE_CONNECT(crawlspace_cavity, wall,"_C_crawlspace_wall");
}
/* -------------------------------------------------------------------------*/
@@ -977,9 +977,9 @@ build_cad_model1(struct building* building)
data_cad = malloc(sizeof(struct data_cad_model1));
building->data_cad = (struct data_cad_model1*)data_cad;
- /* build mandatories elements :
+ /* build mandatories elements :
- floor
- - wall
+ - wall
- roff
*/
@@ -989,10 +989,10 @@ build_cad_model1(struct building* building)
ERR(build_roof(str_cget(&prefix), pg, height, data, &data_cad->roof));
- /* build optionnal elements :
+ /* build optionnal elements :
- intermediate floor
- - external insulation
- - internal insulation
+ - external insulation
+ - internal insulation
- roof insulation
- floor insulation
*/
@@ -1033,7 +1033,7 @@ build_cad_model1(struct building* building)
data_cad->floor_insulation = NULL;
}
- /* build cavities :
+ /* build cavities :
- attic
- habitable
- crawlspace
@@ -1112,7 +1112,7 @@ export_stl_model1
/* roof export */
ERR(scad_stl_export(data_cad->roof, NULL, binary));
-
+
/* intermediate floor export*/
if (data_cad->intermediate_floor) {
ERR(scad_stl_export(data_cad->intermediate_floor, NULL, binary));