Revision: 76627
http://sourceforge.net/p/brlcad/code/76627
Author: brlcad
Date: 2020-08-01 06:44:27 +0000 (Sat, 01 Aug 2020)
Log Message:
-----------
fix idents crash when running from read-only dir
if the output file could not be created, an attempt to free an
unallocate and uninitialized ptbl would cause a bu_bomb. now its on
the stack, so nothing to free, and error messages are updated to be a
bit more helpful.
Modified Paths:
--------------
brlcad/trunk/src/libged/tables/tables.c
Modified: brlcad/trunk/src/libged/tables/tables.c
===================================================================
--- brlcad/trunk/src/libged/tables/tables.c 2020-08-01 04:32:40 UTC (rev
76626)
+++ brlcad/trunk/src/libged/tables/tables.c 2020-08-01 06:44:27 UTC (rev
76627)
@@ -464,22 +464,22 @@
int
ged_tables_core(struct ged *gedp, int argc, const char *argv[])
{
- struct bu_vls tmp_vls = BU_VLS_INIT_ZERO;
- struct bu_vls cmd = BU_VLS_INIT_ZERO;
- struct bu_vls tabvls = BU_VLS_INIT_ZERO;
+ static const char *usage = "file object(s)";
+
+ FILE *ftabvls = NULL;
FILE *test_f = NULL;
- FILE *ftabvls = NULL;
- struct bu_ptbl cur_path;
+ char *timep;
int flag;
int status;
- char *timep;
- time_t now;
size_t i, j;
- const char *usage = "file object(s)";
- struct bu_ptbl *tabobjs = NULL;
-
size_t numreg = 0;
size_t numsol = 0;
+ struct bu_ptbl tabobjs;
+ struct bu_ptbl cur_path;
+ struct bu_vls cmd = BU_VLS_INIT_ZERO;
+ struct bu_vls tabvls = BU_VLS_INIT_ZERO;
+ struct bu_vls tmp_vls = BU_VLS_INIT_ZERO;
+ time_t now;
GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
@@ -499,6 +499,7 @@
}
bu_ptbl_init(&cur_path, 8, "f_tables: cur_path");
+ bu_ptbl_init(&tabobjs, 8, "f_tables: objects");
status = GED_OK;
@@ -522,7 +523,7 @@
/* open the file */
test_f = fopen(argv[1], "w+");
if (test_f == NULL) {
- bu_vls_printf(gedp->ged_result_str, "%s: Can't open %s\n", argv[0],
argv[1]);
+ bu_vls_printf(gedp->ged_result_str, "%s: Can't open file [%s]\n\tMake
sure the directory and file are writable.\n", argv[0], argv[1]);
status = GED_ERROR;
goto end;
}
@@ -545,8 +546,6 @@
tables_header(&tabvls, argc, argv, gedp, timep);
- BU_GET(tabobjs, struct bu_ptbl);
- bu_ptbl_init(tabobjs, 8, "f_tables: objects");
/* make the tables */
for (i = 2; i < (size_t)argc; i++) {
@@ -554,14 +553,14 @@
bu_ptbl_reset(&cur_path);
if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) !=
RT_DIR_NULL)
- tables_new(gedp, tabobjs, dp, &cur_path, (const fastf_t
*)bn_mat_identity, flag, &numreg, &numsol);
+ tables_new(gedp, &tabobjs, dp, &cur_path, (const fastf_t
*)bn_mat_identity, flag, &numreg, &numsol);
else
bu_vls_printf(gedp->ged_result_str, "%s: skip this object\n",
argv[i]);
}
- tables_objs_print(&tabvls, tabobjs, flag);
+ tables_objs_print(&tabvls, &tabobjs, flag);
- bu_vls_printf(gedp->ged_result_str, "Summary written in: %s\n", argv[1]);
+ bu_vls_printf(gedp->ged_result_str, "Summary written to: %s\n", argv[1]);
if (flag == SOL_TABLE || flag == REG_TABLE) {
bu_vls_printf(&tabvls, "\n\nNumber Primitives = %zu Number Regions =
%zu\n",
@@ -577,9 +576,9 @@
bu_vls_printf(gedp->ged_result_str, "Processed %lu Regions\n", numreg);
/* make ordered idents and re-print */
- bu_sort(BU_PTBL_BASEADDR(tabobjs), BU_PTBL_LEN(tabobjs), sizeof(struct
table_obj *), sort_table_objs, NULL);
+ bu_sort(BU_PTBL_BASEADDR(&tabobjs), BU_PTBL_LEN(&tabobjs),
sizeof(struct table_obj *), sort_table_objs, NULL);
- tables_objs_print(&tabvls, tabobjs, flag);
+ tables_objs_print(&tabvls, &tabobjs, flag);
bu_vls_printf(&tabvls, "* 9999999\n* 9999999\n* 9999999\n* 9999999\n*
9999999\n");
}
@@ -586,7 +585,7 @@
ftabvls = fopen(argv[1], "w+");
if (ftabvls == NULL) {
- bu_vls_printf(gedp->ged_result_str, "%s: Can't open %s\n", argv[0],
argv[1]);
+ bu_vls_printf(gedp->ged_result_str, "%s: Can't open file [%s]\n\tMake
sure the directory and file are still writable.\n", argv[0], argv[1]);
status = GED_ERROR;
goto end;
}
@@ -599,8 +598,8 @@
bu_vls_free(&tabvls);
bu_ptbl_free(&cur_path);
- for (i = 0; i < BU_PTBL_LEN(tabobjs); i++) {
- struct table_obj *o = (struct table_obj *)BU_PTBL_GET(tabobjs, i);
+ for (i = 0; i < BU_PTBL_LEN(&tabobjs); i++) {
+ struct table_obj *o = (struct table_obj *)BU_PTBL_GET(&tabobjs, i);
for (j = 0; j < BU_PTBL_LEN(o->tree_objs); j++) {
struct tree_obj *t = (struct tree_obj *)BU_PTBL_GET(o->tree_objs,
j);
bu_vls_free(t->tree);
@@ -613,8 +612,7 @@
BU_PUT(o->path, struct bu_vls);
BU_PUT(o, struct table_obj);
}
- bu_ptbl_free(tabobjs);
- BU_PUT(tabobjs, struct bu_ptbl);
+ bu_ptbl_free(&tabobjs);
return status;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits