stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit 8684b0a69b88d0db671ddbbb6a9011e68eb340d1
parent 0aced7f37e98d25bbe2c85ac243f5eb31f49bcf4
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 12 Jun 2019 11:34:19 +0200

Fix uninitialised struct fields

Diffstat:
Msrc/stardis-app.c | 28++++++++++++++++++++++------
Msrc/stardis-app.h | 12++++++++++++
2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -133,6 +133,7 @@ parse_medium_line(char* line, char** stl_filename, struct description* desc) CHK_TOK(_strupr(strtok(line, " ")), "medium type"); if (strcmp(tk, "SOLID") == 0) { desc->type = DESC_MAT_SOLID; + desc->d.solid = NULL_SOLID; CHK_TOK(strtok(NULL, " "), "medium name"); if (strlen(tk) >= sizeof(desc->d.solid.name)) { @@ -186,8 +187,6 @@ parse_medium_line(char* line, char** stl_filename, struct description* desc) tk = strtok(NULL, "\""); /* Volumic Power is optional */ - desc->d.solid.power = NULL; - desc->d.solid.has_power = 0; if (tk && *(tk + strspn(tk, " \t")) == '\0') { /* Depending of the number of spaces before '"' strtok should * be called once or twice */ @@ -202,6 +201,7 @@ parse_medium_line(char* line, char** stl_filename, struct description* desc) } else if (strcmp(tk, "FLUID") == 0) { desc->type = DESC_MAT_FLUID; + desc->d.fluid = NULL_FLUID; CHK_TOK(strtok(NULL, " "), "medium name"); if (strlen(tk) >= sizeof(desc->d.fluid.name)) { @@ -292,6 +292,7 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc) if (h_solid || h_fluid) { desc->type = h_solid ? DESC_BOUND_H_FOR_SOLID : DESC_BOUND_H_FOR_FLUID; + desc->d.h_boundary = NULL_HBOUND; CHK_TOK(strtok(NULL, " "), "boundary name"); if (strlen(tk) >= sizeof(desc->d.h_boundary.name)) { @@ -352,6 +353,7 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc) } else if (t_solid || t_fluid) { desc->type = t_solid ? DESC_BOUND_T_FOR_SOLID : DESC_BOUND_T_FOR_FLUID; + desc->d.t_boundary = NULL_TBOUND; CHK_TOK(strtok(NULL, " "), "boundary name"); if (strlen(tk) >= sizeof(desc->d.t_boundary.name)) { @@ -399,6 +401,7 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc) } else if (f_solid) { desc->type = DESC_BOUND_F_FOR_SOLID; + desc->d.f_boundary = NULL_FBOUND; CHK_TOK(strtok(NULL, " "), "boundary name"); if (strlen(tk) >= sizeof(desc->d.f_boundary.name)) { @@ -423,6 +426,7 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc) } else if (sf_connect) { desc->type = DESC_SOLID_FLUID_CONNECT; + desc->d.sf_connect = NULL_SFCONNECT; CHK_TOK(strtok(NULL, " "), "boundary name"); if (strlen(tk) >= sizeof(desc->d.sf_connect.name)) { @@ -508,7 +512,8 @@ read_vertices unsigned size; ASSERT(sz < UINT_MAX); size = (unsigned)sz; - htable_vertex_set(vertex2id, &vtx, &size); + res = htable_vertex_set(vertex2id, &vtx, &size); + if (res != RES_OK) return res; sa_push(geometry->vertex, vtx); sa_push(*id2id, size); } @@ -608,7 +613,8 @@ read_triangles ASSERT(sz < UINT_MAX); id = (unsigned)sz; /* Store tri as described by stl_desc regardless of key order */ - htable_triangle_set(triangle2id, &key, &id); + res = htable_triangle_set(triangle2id, &key, &id); + if (res != RES_OK) goto error; sa_push(geometry->triangle, tri); } @@ -659,9 +665,17 @@ read_triangles else { sa_release(packed_indices); sa_release(packed_normals); + packed_indices = NULL; + packed_normals = NULL; } +end: + sa_release(packed_indices); + sa_release(packed_normals); + return res; + error: + goto end; } res_T @@ -757,7 +771,8 @@ geometry_analyse desc_id = sz++; ASSERT(sz == sa_size(stardis->descriptions)); /* Register new medium description */ - htable_descriptions_set(&descriptions, &desc, &desc_id); + res = htable_descriptions_set(&descriptions, &desc, &desc_id); + if (res != RES_OK) goto error; } else { fprintf(stderr, "Duplicate media description found: deduplicated.\n"); desc_id = *p_desc; @@ -796,7 +811,8 @@ geometry_analyse desc_id = sz++; ASSERT(sz == sa_size(stardis->descriptions)); /* Register new boundary description */ - htable_descriptions_set(&descriptions, &desc, &desc_id); + res = htable_descriptions_set(&descriptions, &desc, &desc_id); + if (res != RES_OK) goto error; } else { fprintf(stderr, "Duplicate boundary description found: deduplicated.\n"); desc_id = *p_desc; diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -128,6 +128,8 @@ struct mat_fluid { double cp; char* Tinit; }; +#define NULL_FLUID__ { "", UINT_MAX, 0, 0, 0} +static struct mat_fluid NULL_FLUID = NULL_FLUID__; static void print_fluid(FILE* stream, const struct mat_fluid* f) @@ -227,6 +229,8 @@ struct mat_solid { char* power; int has_power; }; +#define NULL_SOLID__ { "", UINT_MAX, 0, 0, 0, 0, NULL, NULL, 0} +static struct mat_solid NULL_SOLID = NULL_SOLID__; static void print_solid(FILE* stream, const struct mat_solid* s) @@ -364,6 +368,8 @@ struct h_boundary { char* T; int has_emissivity, has_hc; }; +#define NULL_HBOUND__ { "", UINT_MAX, 0, 0, 0, 0, NULL, 0, 0} +static struct h_boundary NULL_HBOUND = NULL_HBOUND__; static void print_h_boundary @@ -510,6 +516,8 @@ struct t_boundary { double hc_max; int has_hc; }; +#define NULL_TBOUND__ { "", UINT_MAX, NULL, NULL, 0, 0, 0} +static struct t_boundary NULL_TBOUND = NULL_TBOUND__; static void print_t_boundary @@ -636,6 +644,8 @@ struct f_boundary { char* flux; struct te_expr* te_flux; }; +#define NULL_FBOUND__ { "", UINT_MAX, NULL, NULL} +static struct f_boundary NULL_FBOUND = NULL_FBOUND__; static void print_f_boundary @@ -716,6 +726,8 @@ struct solid_fluid_connect { double hc_max; int has_emissivity, has_hc; }; +#define NULL_SFCONNECT__ { "", 0, 0, 0, 0, 0, 0} +static struct solid_fluid_connect NULL_SFCONNECT = NULL_SFCONNECT__; static char eq_sf_connect(const struct solid_fluid_connect* a, const struct solid_fluid_connect* b)