From b1995c437f4e385acc3c81c9159c1c69cec6a89e Mon Sep 17 00:00:00 2001 From: Clifford Yapp <238416+starseeker@users.noreply.github.com> Date: Mon, 22 Jul 2024 20:22:29 -0400 Subject: [PATCH] Clear a few static analyzer warnings --- src/conv/off/g-off.c | 5 ++++- src/libbv/polygon.c | 6 ------ src/librt/primitives/arb8/arb8.c | 15 +++++++++------ src/librt/tests/CMakeLists.txt | 2 +- src/librt/tests/rt_perturb.c | 22 ++++++++++------------ src/util/pix-ppm.c | 7 +++++++ 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/conv/off/g-off.c b/src/conv/off/g-off.c index df53cdc3869..be59ca9d86f 100644 --- a/src/conv/off/g-off.c +++ b/src/conv/off/g-off.c @@ -179,8 +179,11 @@ main(int argc, char **argv) *dot = '\0'; bu_strlcat(fig_file, ".fig", size); /* Add required Jack suffix. */ - if ((fp_fig = fopen(fig_file, "wb")) == NULL) + if ((fp_fig = fopen(fig_file, "wb")) == NULL) { perror(fig_file); + bu_exit(1, "ERROR: Unable to open %s\n", fig_file); + } + fprintf(fp_fig, "figure {\n"); /* Walk indicated tree(s). Each region will be output separately */ diff --git a/src/libbv/polygon.c b/src/libbv/polygon.c index 27855ff5b2b..2ed4fe22e99 100644 --- a/src/libbv/polygon.c +++ b/src/libbv/polygon.c @@ -202,8 +202,6 @@ bv_create_polygon_obj(struct bview *v, int flags, struct bv_polygon *p) struct bv_scene_obj * bv_create_polygon(struct bview *v, int flags, int type, point_t *fp) { - bu_log("fp: %f %f %f\n", V3ARGS(*fp)); - struct bv_polygon *p; BU_GET(p, struct bv_polygon); p->type = type; @@ -225,7 +223,6 @@ bv_create_polygon(struct bview *v, int flags, int type, point_t *fp) // This is now the origin point VMOVE(p->origin_point, m_pt); - bu_log("origin_pt: %f %f %f\n", V3ARGS(m_pt)); int pcnt = 1; if (type == BV_POLYGON_CIRCLE) @@ -505,8 +502,6 @@ int bv_update_polygon_circle(struct bv_scene_obj *s, point_t *cp, fastf_t pixel_size) { struct bv_polygon *p = (struct bv_polygon *)s->s_i_data; - bu_log("origin_pt: %f %f %f\n", V3ARGS(p->origin_point)); - bu_log("cp: %f %f %f\n", V3ARGS(*cp)); fastf_t curr_fx, curr_fy; fastf_t r, arc; @@ -523,7 +518,6 @@ bv_update_polygon_circle(struct bv_scene_obj *s, point_t *cp, fastf_t pixel_size bg_plane_pt_at(&pcp, &zpln, fx, fy); r = DIST_PNT_PNT(pcp, p->origin_point); - bu_log("r: %f\n", r); /* use a variable number of segments based on the size of the * circle being created so small circles have few segments and diff --git a/src/librt/primitives/arb8/arb8.c b/src/librt/primitives/arb8/arb8.c index 9ba2d87e1c1..07ae55fecec 100644 --- a/src/librt/primitives/arb8/arb8.c +++ b/src/librt/primitives/arb8/arb8.c @@ -1980,20 +1980,23 @@ rt_arb_calc_planes(struct bu_vls *error_msg_ret, plane_t planes[6], const struct bn_tol *tol) { - register int i, p1, p2, p3; - int type = cgtype - ARB4; /* ARB4 at location 0, ARB5 at 1, etc. */ const int arb_faces[5][24] = rt_arb_faces; + /* ARB4 at location 0, ARB5 at 1, etc. */ + int type = cgtype - ARB4; + if (type < 0 || type > 4) + return -1; + RT_ARB_CK_MAGIC(arb); BN_CK_TOL(tol); - for (i = 0; i < 6; i++) { + for (int i = 0; i < 6; i++) { if (arb_faces[type][i*4] == -1) break; /* faces are done */ - p1 = arb_faces[type][i*4]; - p2 = arb_faces[type][i*4+1]; - p3 = arb_faces[type][i*4+2]; + int p1 = arb_faces[type][i*4]; + int p2 = arb_faces[type][i*4+1]; + int p3 = arb_faces[type][i*4+2]; if (bg_make_plane_3pnts(planes[i], arb->pt[p1], diff --git a/src/librt/tests/CMakeLists.txt b/src/librt/tests/CMakeLists.txt index cade6bc3f14..36ce9de0f91 100644 --- a/src/librt/tests/CMakeLists.txt +++ b/src/librt/tests/CMakeLists.txt @@ -50,7 +50,7 @@ BRLCAD_ADDEXEC(db5_size db5_size.c "librt" TEST) #BRLCAD_ADD_TEST(NAME rt_datum_basic COMMAND rt_datum) # perturb testing -#BRLCAD_ADDEXEC(rt_perturb rt_perturb.c "librt;libwdb" TEST) +BRLCAD_ADDEXEC(rt_perturb rt_perturb.c "librt;libwdb" TEST) #BRLCAD_ADD_TEST(NAME rt_perturb_basic COMMAND rt_perturb) # cyclic path testing diff --git a/src/librt/tests/rt_perturb.c b/src/librt/tests/rt_perturb.c index afa5696e5ce..efd12e2a17b 100644 --- a/src/librt/tests/rt_perturb.c +++ b/src/librt/tests/rt_perturb.c @@ -65,13 +65,12 @@ main(int UNUSED(argc), char *argv[]) struct rt_db_internal *ointern = NULL; if (intern.idb_meth && intern.idb_meth->ft_perturb) { intern.idb_meth->ft_perturb(&ointern, &intern, 0, 0, 2); + wdp = db_diradd(dbip, "rcc_perturb.s", RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&ointern->idb_type); + rt_db_put_internal(wdp, dbip, ointern, &rt_uniresource); + rt_db_free_internal(ointern); + BU_PUT(ointern, struct rt_db_internal); + db_update_nref(dbip, &rt_uniresource); } - - wdp = db_diradd(dbip, "rcc_perturb.s", RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&ointern->idb_type); - rt_db_put_internal(wdp, dbip, ointern, &rt_uniresource); - rt_db_free_internal(ointern); - BU_PUT(ointern, struct rt_db_internal); - db_update_nref(dbip, &rt_uniresource); } { @@ -127,13 +126,12 @@ main(int UNUSED(argc), char *argv[]) struct rt_db_internal *ointern = NULL; if (intern.idb_meth && intern.idb_meth->ft_perturb) { intern.idb_meth->ft_perturb(&ointern, &intern, 0, 0, 100); + wdp = db_diradd(dbip, "arb_perturb.s", RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&ointern->idb_type); + rt_db_put_internal(wdp, dbip, ointern, &rt_uniresource); + rt_db_free_internal(ointern); + BU_PUT(ointern, struct rt_db_internal); + db_update_nref(dbip, &rt_uniresource); } - - wdp = db_diradd(dbip, "arb_perturb.s", RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&ointern->idb_type); - rt_db_put_internal(wdp, dbip, ointern, &rt_uniresource); - rt_db_free_internal(ointern); - BU_PUT(ointern, struct rt_db_internal); - db_update_nref(dbip, &rt_uniresource); } db_close(dbip); diff --git a/src/util/pix-ppm.c b/src/util/pix-ppm.c index 0c4eb11228c..0b9337d669d 100644 --- a/src/util/pix-ppm.c +++ b/src/util/pix-ppm.c @@ -102,10 +102,17 @@ get_args(int argc, char *argv[], long *width, long *height) fileinput++; } + if (!infp) + bu_exit(0, "ERROR: infp is null\n"); + if (isatty(fileno(infp))) { bu_log("ERROR: %s will not read pix data from a tty\n", bu_getprogname()); return 0; /* usage */ } + + if (!outfp) + bu_exit(0, "ERROR: outfp is null\n"); + if (isatty(fileno(outfp))) { bu_exit(0, "ERROR: %s will not write ppm data to a tty\n", bu_getprogname()); }