Revision: 56641
http://sourceforge.net/p/brlcad/code/56641
Author: r_weiss
Date: 2013-08-06 19:27:27 +0000 (Tue, 06 Aug 2013)
Log Message:
-----------
Fixed a bug in the fast4-g converter where memory was corrupted when the
group_head list became larger than its allocated size. Changed the code to
allow the group_head list to grow dynamically.
Modified Paths:
--------------
brlcad/trunk/src/conv/fast4-g.c
Modified: brlcad/trunk/src/conv/fast4-g.c
===================================================================
--- brlcad/trunk/src/conv/fast4-g.c 2013-08-06 19:20:45 UTC (rev 56640)
+++ brlcad/trunk/src/conv/fast4-g.c 2013-08-06 19:27:27 UTC (rev 56641)
@@ -196,6 +196,7 @@
static int group_id=(-1); /* Group identification number from
SECTION card */
static int comp_id=(-1); /* Component identification number from
SECTION card */
static int region_id=0; /* Region id number (group id no X 1000
+ component id no) */
+static int region_id_max=0;
static char field[9]; /* Space for storing one field from an
input line */
static char vehicle[17]; /* Title for BRL-CAD model from VEHICLE
card */
static int name_count; /* Count of number of times this
name_name has been used */
@@ -210,7 +211,8 @@
static int *region_list; /* array of region_ids to be processed
*/
static int region_list_len=0; /* actual length of the malloc'd
region_list array */
static int f4_do_plot=0; /* flag indicating plot file should be
created */
-static struct wmember group_head[11]; /* Lists of regions for groups */
+static struct wmember *group_head = (struct wmember *)NULL; /* Lists of
regions for groups */
+static ssize_t group_head_cnt=0;
static struct wmember hole_head; /* List of regions used as holes (not
solid parts of model) */
static struct bu_ptbl stack; /* Stack for traversing name_tree */
static struct bu_ptbl stack2; /* Stack for traversing name_tree */
@@ -520,6 +522,10 @@
new_ptr->name = bu_strdup(name);
new_ptr->magic = NAME_TREE_MAGIC;
+ if (reg_id > region_id_max) {
+ region_id_max = reg_id;
+ }
+
if (!name_root) {
name_root = new_ptr;
} else {
@@ -882,6 +888,33 @@
if (!ptr->in_comp_group && ptr->region_id > 0 &&
!is_a_hole(ptr->region_id)) {
/* add this component to a series */
+
+ if (!group_head || ptr->region_id > region_id_max) {
+ struct wmember *new_head;
+ ssize_t new_cnt, i;
+ struct bu_list *list_first;
+
+ new_cnt = (ssize_t)ceil(region_id_max/1000.0);
+ new_head = (struct wmember *)bu_calloc(new_cnt, sizeof(struct
wmember), "group_head list");
+ bu_log("ptr->region_id=%d region_id_max=%d new_cnt=%ld\n",
ptr->region_id, region_id_max, new_cnt);
+
+ for (i = 0 ; i < new_cnt ; i++) {
+ BU_LIST_INIT(&new_head[i].l);
+ if (i < group_head_cnt) {
+ if (BU_LIST_NON_EMPTY(&group_head[i].l)) {
+ list_first = BU_LIST_FIRST(bu_list,
&group_head[i].l);
+ BU_LIST_DEQUEUE(&group_head[i].l);
+ BU_LIST_INSERT(list_first, &new_head[i].l);
+ }
+ }
+ }
+ if (group_head) {
+ bu_free(group_head, "old group_head");
+ }
+ group_head = new_head;
+ group_head_cnt = new_cnt;
+ }
+
(void)mk_addmember(ptr->name, &group_head[ptr->region_id/1000].l,
NULL, WMOP_UNION);
ptr->in_comp_group = 1;
}
@@ -904,7 +937,7 @@
Add_stragglers_to_groups();
- for (group_no=0; group_no < 11; group_no++) {
+ for (group_no=0; group_no < group_head_cnt; group_no++) {
char name[MAX_LINE_SIZE] = {0};
if (BU_LIST_IS_EMPTY(&group_head[group_no].l))
@@ -2834,7 +2867,6 @@
int
main(int argc, char **argv)
{
- int i;
int c;
char *plot_file = NULL;
char *color_file = NULL;
@@ -2940,9 +2972,6 @@
bu_ptbl_init(&stack, 64, " &stack ");
bu_ptbl_init(&stack2, 64, " &stack2 ");
- for (i=0; i<11; i++)
- BU_LIST_INIT(&group_head[i].l);
-
BU_LIST_INIT(&hole_head.l);
if (!quiet)
@@ -2985,6 +3014,8 @@
if (!quiet)
bu_log("%d components converted\n", comp_count);
+ bu_free(group_head, "group_head");
+
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits