Revision: 71806 http://sourceforge.net/p/brlcad/code/71806 Author: starseeker Date: 2018-09-24 20:47:40 +0000 (Mon, 24 Sep 2018) Log Message: ----------- Add some guards for null set_var variables in bu_opt callbacks that were missing them
Modified Paths: -------------- brlcad/trunk/src/brlman/brlman.c brlcad/trunk/src/conv/g-obj.c brlcad/trunk/src/conv/gcv/gcv.c brlcad/trunk/src/conv/step/step-g/step-g.cpp brlcad/trunk/src/libgcv/plugins/obj/obj_read.c brlcad/trunk/src/libged/ged_util.c brlcad/trunk/src/nirt/main.cxx brlcad/trunk/src/rtwizard/main.c Modified: brlcad/trunk/src/brlman/brlman.c =================================================================== --- brlcad/trunk/src/brlman/brlman.c 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/brlman/brlman.c 2018-09-24 20:47:40 UTC (rev 71806) @@ -83,15 +83,19 @@ { int i = 0; struct bu_vls *lang = (struct bu_vls *)l; - int ret = bu_opt_vls(msg, argc, argv, (void *)l); - if (ret == -1) return -1; - if (bu_vls_strlen(lang) != 2) return -1; - /* Only return valid if we've got one of the ISO639-1 lang codes */ - while (iso639_1[i]) { - if (BU_STR_EQUAL(bu_vls_addr(lang), iso639_1[i])) return ret; - i++; + if (lang) { + int ret = bu_opt_vls(msg, argc, argv, (void *)l); + if (ret == -1) return -1; + if (bu_vls_strlen(lang) != 2) return -1; + /* Only return valid if we've got one of the ISO639-1 lang codes */ + while (iso639_1[i]) { + if (BU_STR_EQUAL(bu_vls_addr(lang), iso639_1[i])) return ret; + i++; + } + return -1; + } else { + return -1; } - return -1; } Modified: brlcad/trunk/src/conv/g-obj.c =================================================================== --- brlcad/trunk/src/conv/g-obj.c 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/conv/g-obj.c 2018-09-24 20:47:40 UTC (rev 71806) @@ -91,60 +91,80 @@ static int print_help = 0; static int -parse_tol_abs(struct bu_vls *error_msg, int argc, const char **argv, void *UNUSED(set_var)) +parse_tol_abs(struct bu_vls *error_msg, int argc, const char **argv, void *set_var) { int ret; BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "absolute tolerance"); - ret = bu_opt_fastf_t(error_msg, argc, argv, (void *)&(ttol.abs)); - ttol.rel = 0.0; - return ret; + if (set_var) { + ret = bu_opt_fastf_t(error_msg, argc, argv, (void *)&(ttol.abs)); + ttol.rel = 0.0; + return ret; + } else { + return -1; + } } static int -parse_tol_norm(struct bu_vls *error_msg, int argc, const char **argv, void *UNUSED(set_var)) +parse_tol_norm(struct bu_vls *error_msg, int argc, const char **argv, void *set_var) { int ret; BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "normal tolerance"); - ret = bu_opt_fastf_t(error_msg, argc, argv, (void *)&(ttol.norm)); - ttol.rel = 0.0; - return ret; + if (set_var) { + ret = bu_opt_fastf_t(error_msg, argc, argv, (void *)&(ttol.norm)); + ttol.rel = 0.0; + return ret; + } else { + return -1; + } } static int -parse_tol_dist(struct bu_vls *error_msg, int argc, const char **argv, void *UNUSED(set_var)) +parse_tol_dist(struct bu_vls *error_msg, int argc, const char **argv, void *set_var) { int ret; BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "distance tolerance"); - ret = bu_opt_fastf_t(error_msg, argc, argv, (void *)&(tol.dist)); - tol.dist_sq = tol.dist * tol.dist; - rt_pr_tol(&tol); - return ret; + if (set_var) { + ret = bu_opt_fastf_t(error_msg, argc, argv, (void *)&(tol.dist)); + tol.dist_sq = tol.dist * tol.dist; + rt_pr_tol(&tol); + return ret; + } else { + return -1; + } } static int -parse_debug_rt(struct bu_vls *error_msg, int argc, const char **argv, void *UNUSED(set_var)) +parse_debug_rt(struct bu_vls *error_msg, int argc, const char **argv, void *set_var) { BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "debug rt"); - sscanf(argv[0], "%x", (unsigned int *)&RTG.debug); - return 1; + if (set_var) { + sscanf(argv[0], "%x", (unsigned int *)&RTG.debug); + return 1; + } else { + return -1; + } } static int -parse_debug_nmg(struct bu_vls *error_msg, int argc, const char **argv, void *UNUSED(set_var)) +parse_debug_nmg(struct bu_vls *error_msg, int argc, const char **argv, void *set_var) { BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "debug nmg"); - sscanf(argv[0], "%x", (unsigned int *)&nmg_debug); - NMG_debug = nmg_debug; - return 1; + if (set_var) { + sscanf(argv[0], "%x", (unsigned int *)&nmg_debug); + NMG_debug = nmg_debug; + return 1; + } else { + return -1; + } } @@ -158,8 +178,8 @@ {"a", "", "#", parse_tol_abs, &ttol, "absolute tolerance"}, {"n", "", "#", parse_tol_norm, &ttol, "surface normal tolerance"}, {"D", "", "#", parse_tol_dist, &tol, "distance tolerance"}, - {"x", "", "level", parse_debug_rt, NULL, "set RT debug flag"}, - {"X", "", "level", parse_debug_nmg, NULL, "set NMG debug flag"}, + {"x", "", "level", parse_debug_rt, &RTG.debug, "set RT debug flag"}, + {"X", "", "level", parse_debug_nmg, &nmg_debug, "set NMG debug flag"}, {"e", "", "error_file", bu_opt_str, &error_file, "error file name"}, {"o", "", "output.obj", bu_opt_str, &output_file, "output file name"}, {"P", "", "#", bu_opt_int, &ncpu, "number of CPUs"}, Modified: brlcad/trunk/src/conv/gcv/gcv.c =================================================================== --- brlcad/trunk/src/conv/gcv/gcv.c 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/conv/gcv/gcv.c 2018-09-24 20:47:40 UTC (rev 71806) @@ -56,6 +56,8 @@ int args_used = 0; struct gcv_fmt_opts *gfo = (struct gcv_fmt_opts *)set_var; + if (!gfo) return -1; + if (!argv || argc < 1 ) return 0; for (i = 0; i < argc; i++) { Modified: brlcad/trunk/src/conv/step/step-g/step-g.cpp =================================================================== --- brlcad/trunk/src/conv/step/step-g/step-g.cpp 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/conv/step/step-g/step-g.cpp 2018-09-24 20:47:40 UTC (rev 71806) @@ -67,8 +67,12 @@ BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "-O"); ofile->overwrite = true; - ret = bu_opt_str(error_msg, argc, argv, &ofile->filename); - return ret; + if (ofile) { + ret = bu_opt_str(error_msg, argc, argv, &ofile->filename); + return ret; + } else { + return -1; + } } int Modified: brlcad/trunk/src/libgcv/plugins/obj/obj_read.c =================================================================== --- brlcad/trunk/src/libgcv/plugins/obj/obj_read.c 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/libgcv/plugins/obj/obj_read.c 2018-09-24 20:47:40 UTC (rev 71806) @@ -3102,6 +3102,8 @@ BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "parse_grouping_option"); + if (!value) return -1; + if (!bu_strcmp(argv[0], "group")) *value = 'g'; else if (!bu_strcmp(argv[0], "material")) @@ -3128,6 +3130,8 @@ BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "parse_mode_option"); + if (!options) return -1; + if (!bu_strcmp(argv[0], "bot")) { options->mode_option = 'b'; } else if (!bu_strcmp(argv[0], "nmg")) { @@ -3152,6 +3156,8 @@ BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "parse_bot_thickness_option"); + if (!options) return -1; + if (bu_opt_fastf_t(error_msg, argc, argv, &options->bot_thickness) != 1) return -1; @@ -3171,7 +3177,9 @@ { int * const value = (int *)set_var; - *value = IGNR_NORM; + if (value) { + *value = IGNR_NORM; + } return 0; } @@ -3183,6 +3191,8 @@ BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "parse_open_bot_output_mode_option"); + if (!value ) return -1; + if (!bu_strcmp(argv[0], "nocos")) *value = RT_BOT_PLATE_NOCOS; else if (!bu_strcmp(argv[0], "plate")) @@ -3203,7 +3213,9 @@ { int * const value = (int *)set_var; - *value = PLOT_ON; + if (value) { + *value = PLOT_ON; + } return 0; } @@ -3211,17 +3223,24 @@ HIDDEN int parse_bot_orientation_option(struct bu_vls *error_msg, int argc, const char **argv, void *set_var) { + int have_orientation = 0; int * const value = (int *)set_var; BU_OPT_CHECK_ARGV0(error_msg, argc, argv, "parse_bot_orientation_option"); - if (!bu_strcmp(argv[0], "unoriented")) + if (!bu_strcmp(argv[0], "unoriented")) { *value = RT_BOT_UNORIENTED; - else if (!bu_strcmp(argv[0], "ccw")) + have_orientation = 1; + } + if (!bu_strcmp(argv[0], "ccw")) { *value = RT_BOT_CCW; - else if (!bu_strcmp(argv[0], "cw")) + have_orientation = 1; + } + if (!bu_strcmp(argv[0], "cw")) { *value = RT_BOT_CW; - else { + have_orientation = 1; + } + if (!have_orientation) { bu_vls_printf(error_msg, "invalid BoT orientation mode\n"); return -1; } Modified: brlcad/trunk/src/libged/ged_util.c =================================================================== --- brlcad/trunk/src/libged/ged_util.c 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/libged/ged_util.c 2018-09-24 20:47:40 UTC (rev 71806) @@ -279,7 +279,9 @@ _ged_vopt(struct bu_vls *UNUSED(msg), int UNUSED(argc), const char **UNUSED(argv), void *set_var) { int *v_set = (int *)set_var; - (*v_set) = (*v_set) + 1; + if (v_set) { + (*v_set) = (*v_set) + 1; + } return 0; } Modified: brlcad/trunk/src/nirt/main.cxx =================================================================== --- brlcad/trunk/src/nirt/main.cxx 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/nirt/main.cxx 2018-09-24 20:47:40 UTC (rev 71806) @@ -155,7 +155,9 @@ _dequeue_scripts(struct bu_vls *UNUSED(msg), int UNUSED(argc), const char **UNUSED(argv), void *set_var) { std::vector<std::string> *init_scripts = (std::vector<std::string> *)set_var; - init_scripts->clear(); + if (set_var) { + init_scripts->clear(); + } return 0; } @@ -164,7 +166,9 @@ { std::vector<std::string> *init_scripts = (std::vector<std::string> *)set_var; BU_OPT_CHECK_ARGV0(msg, argc, argv, "nirt script enqueue"); - init_scripts->push_back(argv[0]); + if (set_var) { + init_scripts->push_back(argv[0]); + } return 1; } @@ -173,7 +177,9 @@ { std::set<std::string> *attrs = (std::set<std::string> *)set_var; BU_OPT_CHECK_ARGV0(msg, argc, argv, "nirt attr enqueue"); - attrs->insert(argv[0]); + if (set_var) { + attrs->insert(argv[0]); + } return 1; } @@ -199,16 +205,22 @@ bu_vls_free(&str); if (!file.is_open()) return -1; while (std::getline(file, s)) { - sfd->init_scripts->push_back(s); + if (sfd) { + sfd->init_scripts->push_back(s); + } } } else { while (std::getline(file, s)) { - sfd->init_scripts->push_back(s); + if (sfd) { + sfd->init_scripts->push_back(s); + } } } - bu_vls_sprintf(sfd->filename, "%s", argv[0]); - sfd->file_cnt++; + if (sfd) { + bu_vls_sprintf(sfd->filename, "%s", argv[0]); + sfd->file_cnt++; + } return 1; } @@ -219,13 +231,13 @@ int *oval = (int *)set_var; BU_OPT_CHECK_ARGV0(msg, argc, argv, "nirt overlap handle"); if (BU_STR_EQUAL(argv[0], "resolve") || BU_STR_EQUAL(argv[0], "0")) { - (*oval) = OVLP_RESOLVE; + if (oval) (*oval) = OVLP_RESOLVE; } else if (BU_STR_EQUAL(argv[0], "rebuild_fastgen") || BU_STR_EQUAL(argv[0], "1")) { - (*oval) = OVLP_REBUILD_FASTGEN; + if (oval) (*oval) = OVLP_REBUILD_FASTGEN; } else if (BU_STR_EQUAL(argv[0], "rebuild_all") || BU_STR_EQUAL(argv[0], "2")) { - (*oval) = OVLP_REBUILD_ALL; + if (oval) (*oval) = OVLP_REBUILD_ALL; } else if (BU_STR_EQUAL(argv[0], "retain") || BU_STR_EQUAL(argv[0], "3")) { - (*oval) = OVLP_RETAIN; + if (oval) (*oval) = OVLP_RETAIN; } else { bu_log("Illegal overlap_claims specification: '%s'\n", argv[0]); return -1; Modified: brlcad/trunk/src/rtwizard/main.c =================================================================== --- brlcad/trunk/src/rtwizard/main.c 2018-09-24 20:06:06 UTC (rev 71805) +++ brlcad/trunk/src/rtwizard/main.c 2018-09-24 20:47:40 UTC (rev 71806) @@ -345,9 +345,13 @@ opt_width(struct bu_vls *msg, int argc, const char **argv, void *settings) { struct rtwizard_settings *s = (struct rtwizard_settings *)settings; - int ret = bu_opt_int(msg, argc, argv, (void *)&s->width); - if (ret != -1) s->width_set = 1; - return ret; + if (s) { + int ret = bu_opt_int(msg, argc, argv, (void *)&s->width); + if (ret != -1) s->width_set = 1; + return ret; + } else { + return -1; + } } @@ -355,9 +359,13 @@ opt_height(struct bu_vls *msg, int argc, const char **argv, void *settings) { struct rtwizard_settings *s = (struct rtwizard_settings *)settings; - int ret = bu_opt_int(msg, argc, argv, (void *)&s->height); - if (ret != -1) s->height_set = 1; - return ret; + if (s) { + int ret = bu_opt_int(msg, argc, argv, (void *)&s->height); + if (ret != -1) s->height_set = 1; + return ret; + } else { + return -1; + } } int @@ -364,13 +372,17 @@ opt_size(struct bu_vls *msg, int argc, const char **argv, void *settings) { struct rtwizard_settings *s = (struct rtwizard_settings *)settings; - int ret = bu_opt_int(msg, argc, argv, (void *)&s->size); - if (ret != -1) { - s->size_set = 1; - if (!s->width_set) s->width = s->size; - if (!s->height_set) s->height = s->size; + if (s) { + int ret = bu_opt_int(msg, argc, argv, (void *)&s->size); + if (ret != -1) { + s->size_set = 1; + if (!s->width_set) s->width = s->size; + if (!s->height_set) s->height = s->size; + } + return ret; + } else { + return -1; } - return ret; } int @@ -402,7 +414,9 @@ /* TODO - use quote/unquote routines to scrub names... */ for (i = 0; i < acnum; i++) { - bu_ptbl_ins(t, (long *)bu_strdup(avnum[i])); + if (t) { + bu_ptbl_ins(t, (long *)bu_strdup(avnum[i])); + } } bu_free(objs, "string dup"); bu_free(avnum, "array memory"); @@ -426,7 +440,9 @@ return -1; } - (*letter) = argv[0][0]; + if (letter) { + (*letter) = argv[0][0]; + } return 1; } @@ -475,10 +491,12 @@ bu_free(str1, "free tmp str"); /* If we got here, we do have four numbers */ if (have_four) { - (*q)[0] = q1; - (*q)[1] = q2; - (*q)[2] = q3; - (*q)[3] = q4; + if (q) { + (*q)[0] = q1; + (*q)[1] = q2; + (*q)[2] = q3; + (*q)[3] = q4; + } return 1; } } else { @@ -505,10 +523,12 @@ if (msg) bu_vls_sprintf(msg, "Not a number: %s.\n", argv[3]); return -1; } - (*q)[0] = q1; - (*q)[1] = q2; - (*q)[2] = q3; - (*q)[3] = q4; + if (q) { + (*q)[0] = q1; + (*q)[1] = q2; + (*q)[2] = q3; + (*q)[3] = q4; + } return 1; } else { if (msg) bu_vls_sprintf(msg, "No valid quaternion found: %s\n", argv[0]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits