Revision: 41343
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41343&view=rev
Author:   brlcad
Date:     2010-11-12 22:11:21 +0000 (Fri, 12 Nov 2010)

Log Message:
-----------
remove several more instances of MAXARGS, replacing with calls to allocate/free 
dynamic memory that is sized with reasonable boundary limits

Modified Paths:
--------------
    brlcad/trunk/src/conv/bot_dump.c
    brlcad/trunk/src/remrt/rtsrv.c

Modified: brlcad/trunk/src/conv/bot_dump.c
===================================================================
--- brlcad/trunk/src/conv/bot_dump.c    2010-11-12 21:58:16 UTC (rev 41342)
+++ brlcad/trunk/src/conv/bot_dump.c    2010-11-12 22:11:21 UTC (rev 41343)
@@ -42,7 +42,7 @@
     int i, j;
     int db_index;
     char c;
-    const char *av[MAXARGS];
+    const char **av;
     struct ged *gedp;
 
     bu_optind = 1;
@@ -67,6 +67,8 @@
        bu_exit(1, usage, argv[0]);
     }
 
+    av = bu_calloc(argc, sizeof(char *), "alloc argv copy");
+
     db_index = bu_optind;
     for (i = j = 0; i < argc; ++i) {
        if (i == db_index)
@@ -85,6 +87,7 @@
     if (bu_vls_strlen(&gedp->ged_result_str) > 0)
        bu_log("%s", bu_vls_addr(&gedp->ged_result_str));
     ged_close(gedp);
+    bu_free(av, "free argv copy");
 
     return 0;
 }

Modified: brlcad/trunk/src/remrt/rtsrv.c
===================================================================
--- brlcad/trunk/src/remrt/rtsrv.c      2010-11-12 21:58:16 UTC (rev 41342)
+++ brlcad/trunk/src/remrt/rtsrv.c      2010-11-12 22:11:21 UTC (rev 41343)
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <ctype.h>
 #ifdef HAVE_SYS_TIME_H
 #  include <sys/time.h>
 #endif
@@ -433,26 +434,35 @@
 void
 ph_dirbuild(struct pkg_conn *pc, char *buf)
 {
-#define MAXARGS 1024
-    char       *argv[MAXARGS+1];
-    struct rt_i *rtip;
-    int        n;
+    long max_argc = 0;
+    char **argv = NULL;
+    struct rt_i *rtip = NULL;
+    int        n = 0;
 
     if ( debug )  fprintf(stderr, "ph_dirbuild: %s\n", buf );
 
-    if ( (bu_argv_from_string( argv, MAXARGS, buf )) <= 0 )  {
+    for (n = 0; n < strlen(buf); n++) {
+       if (isspace(buf[n]))
+           max_argc++;
+    }
+    argv = bu_calloc(max_argc+1, sizeof(char *), "alloc argv");
+
+    if ( (bu_argv_from_string( argv, max_argc, buf )) <= 0 )  {
        /* No words in input */
        (void)free(buf);
+       bu_free(argv, "free argv");
        return;
     }
 
     if ( seen_dirbuild )  {
        bu_log("ph_dirbuild:  MSG_DIRBUILD already seen, ignored\n");
        (void)free(buf);
+       bu_free(argv, "free argv");
        return;
     }
 
     title_file = bu_strdup(argv[0]);
+    bu_free(argv, "free argv");
 
     /* Build directory of GED database */
     if ( (rtip=rt_dirbuild( title_file, idbuf, sizeof(idbuf) )) == RTI_NULL )
@@ -482,9 +492,10 @@
 void
 ph_gettrees(struct pkg_conn *pc, char *buf)
 {
-#define MAXARGS 1024
-    char       *argv[MAXARGS+1];
-    int        argc;
+    int n = 0;
+    long max_argc = 0;
+    char **argv = NULL;
+    int        argc = 0;
     struct rt_i *rtip = ap.a_rt_i;
 
     RT_CK_RTI(rtip);
@@ -502,9 +513,16 @@
        rtip->rti_tol.para = 1 - rt_perp_tol;
     }
 
-    if ( (argc = bu_argv_from_string( argv, MAXARGS, buf )) <= 0 )  {
+    for (n = 0; n < strlen(buf); n++) {
+       if (isspace(buf[n]))
+           max_argc++;
+    }
+    argv = bu_calloc(max_argc+1, sizeof(char *), "alloc argv");
+
+    if ( (argc = bu_argv_from_string( argv, max_argc, buf )) <= 0 )  {
        /* No words in input */
        (void)free(buf);
+       bu_free(argv, "free argv");
        return;
     }
     title_obj = bu_strdup(argv[0]);
@@ -522,6 +540,7 @@
     /* Load the desired portion of the model */
     if ( rt_gettrees(rtip, argc, (const char **)argv, npsw) < 0 )
        fprintf(stderr, "rt_gettrees(%s) FAILED\n", argv[0]);
+    bu_free(argv, "free argv");
 
     /* In case it changed from startup time via an OPT command */
     if ( npsw > 1 )  {


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

------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to