Revision: 45974
          http://brlcad.svn.sourceforge.net/brlcad/?rev=45974&view=rev
Author:   bhinesley
Date:     2011-08-14 07:18:56 +0000 (Sun, 14 Aug 2011)

Log Message:
-----------
Initializing cur_arg pointer to wrong value after freeing, resulted in stepping 
over two nodes in linked list rather than one.  Missing braces for if 
statements causing havoc. Attempt to free a shallow copy of a union edit_cmd 
(wasn't causing any problems though, since its contents were first replaced 
with NULL pointers, which was detected by the freeing function and therefore 
nothing was freed). Simplified and clarified a few other small things. Still 
some problems with multiple -x/-y/-z uses in a single argument.

Modified Paths:
--------------
    brlcad/trunk/src/libged/edit.c

Modified: brlcad/trunk/src/libged/edit.c
===================================================================
--- brlcad/trunk/src/libged/edit.c      2011-08-14 04:13:54 UTC (rev 45973)
+++ brlcad/trunk/src/libged/edit.c      2011-08-14 07:18:56 UTC (rev 45974)
@@ -1331,20 +1331,24 @@
                    return GED_ERROR;
 
                /* consolidate */
-               if (cur_arg->coords_used & EDIT_COORD_X)
+               if (cur_arg->coords_used & EDIT_COORD_X) {
                    prev_arg->coords_used |= EDIT_COORD_X;
                    *prev_arg->vector[0] = *cur_arg->vector[0];
-               if (cur_arg->coords_used & EDIT_COORD_Y)
+               }
+               if (cur_arg->coords_used & EDIT_COORD_Y) {
                    prev_arg->coords_used |= EDIT_COORD_Y;
                    *prev_arg->vector[1] = *cur_arg->vector[1];
-               if (cur_arg->coords_used & EDIT_COORD_Z)
+               }
+               if (cur_arg->coords_used & EDIT_COORD_Z) {
                    prev_arg->coords_used |= EDIT_COORD_Z;
                    *prev_arg->vector[2] = *cur_arg->vector[2];
+               }
 
                /* remove consolidated argument */
                next_arg = cur_arg->next;
                edit_arg_free(cur_arg);
-               prev_arg->next = cur_arg = next_arg;
+               cur_arg = prev_arg;
+               prev_arg->next = next_arg;
            } else {
                prev_arg = cur_arg; /* the args are incompatible */
            }
@@ -1856,7 +1860,7 @@
      * be copied later if there are any batch modifiers to expand.
      */
     arg_head = subcmd->cmd->get_arg_head(subcmd, i++);
-    ++num_arg_heads_set; /* an object is always set */
+    ++num_arg_heads_set; /* a target object is always set */
     for (cur_arg = *arg_head; cur_arg; cur_arg = cur_arg->next) {
        /* target objects must be... objects */
        BU_ASSERT(cur_arg->object);
@@ -1896,12 +1900,16 @@
     if (subcmd->cmd->exec(gedp, subcmd) == GED_ERROR)
        return GED_ERROR;
        
-    /* iterate over each set of batch args and execute subcmd */
+    /* create a copy to iterate over groups of batch args; note that
+     * the copy is shallow and *must not be freed*
+     */
     subcmd_iter.cmd = subcmd->cmd;
     edit_cmd_init(&subcmd_iter);
     edit_cmd_sduplicate(&subcmd_iter, subcmd);
-    i = 0; /* reinit for get_arg_head() */
-    arg_head = subcmd_iter.cmd->get_arg_head(&subcmd_iter, i++);
+    arg_head = subcmd_iter.cmd->get_arg_head(&subcmd_iter, 0);
+
+    /* iterate over each set of batch args and execute subcmd */
+    i = 1; /* reinit for get_arg_head() */
     do {
        num_args_set = 0;
 
@@ -1919,7 +1927,6 @@
            return GED_ERROR;
        ret = subcmd_iter.cmd->exec(gedp, &subcmd_iter);
     } while ((ret != GED_ERROR));
-    edit_cmd_free(&subcmd_iter);
 
     return ret;
 }
@@ -2156,7 +2163,7 @@
      */
     if (((arg->coords_used & EDIT_COORDS_ALL) == EDIT_COORDS_ALL) &&
        (arg->coords_used & ~EDIT_COORDS_ALL))
-       arg->coords_used = arg->coords_used >> 3;
+       arg->coords_used >>= 3;
 
     /* these flags are only for internal use */
     /* FIXME: exactly why they should be internalized, and not


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy 
to use, easy to manage, easy to install, easy to extend. 
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to