Revision: 41794
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41794&view=rev
Author:   starseeker
Date:     2010-12-23 15:54:20 +0000 (Thu, 23 Dec 2010)

Log Message:
-----------
Start cleaning up dem-g - first, fix the variable size array declarations.  
This seems to work in testing on the Mac

Modified Paths:
--------------
    brlcad/branches/cmake/src/conv/dem-g.c

Modified: brlcad/branches/cmake/src/conv/dem-g.c
===================================================================
--- brlcad/branches/cmake/src/conv/dem-g.c      2010-12-23 13:39:12 UTC (rev 
41793)
+++ brlcad/branches/cmake/src/conv/dem-g.c      2010-12-23 15:54:20 UTC (rev 
41794)
@@ -1563,31 +1563,32 @@
     FILE *fp4;
     long int offset = 0;
     long int column = 0;
+    unsigned short int *buf3;
     unsigned short int buf4 = 0;
 
-    /* FIXME: C90 forbids variable size array declarations.  use 
bu_malloc/bu_free instead. */
-    /* size of buf3 determined at run time */
-    unsigned short int buf3[*in_ydim];
+    buf3 = bu_malloc(sizeof(unsigned short int) * (*in_ydim), "buf3");
 
     if ((fp4=fopen(in_dsp_output_filename, "wb")) == NULL) {
         bu_log("Could not open '%s' for write.\n", in_dsp_output_filename);
+       bu_free(buf3, "buf3");
         return BRLCAD_ERROR;
     }
     for (offset = 0; offset <= *in_ydim-1; offset++) {
         if ((fp3=fopen(in_temp_filename, "rb")) == NULL) {
             bu_log("Could not open '%s' for read.\n", in_temp_filename);
             fclose(fp4);
-            return BRLCAD_ERROR;
+           bu_free(buf3, "buf3");
+           return BRLCAD_ERROR;
         } 
         for (column = 1; column <= *in_xdim; column++) {
-            fread(buf3, sizeof(buf3[0]), sizeof(buf3)/sizeof(buf3[0]), fp3);
-            buf4 = buf3[offset];
+            fread(buf3, sizeof(unsigned short int), sizeof(unsigned short int) 
* (*in_ydim)/sizeof(unsigned short int), fp3);
+            buf4 = *(buf3 + offset);
             fwrite(&buf4, sizeof(buf4), 1, fp4);   
         }
         fclose(fp3);
     }
     fclose(fp4);
-
+    bu_free(buf3, "buf3");
     return BRLCAD_OK;
 }
 
@@ -2079,12 +2080,16 @@
     remove_whitespace(av[1]);
     string_length = strlen(av[1]) + 5;
 
-    /* FIXME: C90 forbids variable size array declarations.  use 
bu_malloc/bu_free instead. */
-    char input_filename[string_length];          /* dem input file path and 
file name */
-    char temp_filename[string_length];           /* temp file path and file 
name */
-    char dsp_output_filename[string_length];     /* dsp output file path and 
file name */
-    char model_output_filename[string_length];   /* model output file path and 
file name */
+    char *input_filename;
+    char *temp_filename;
+    char *dsp_output_filename;
+    char *model_output_filename;
 
+    input_filename = bu_malloc(sizeof(char *) * string_length, 
"input_filename");
+    temp_filename = bu_malloc(sizeof(char *) * string_length, "temp_filename");
+    dsp_output_filename = bu_malloc(sizeof(char *) * string_length, 
"dsp_output_filename");
+    model_output_filename = bu_malloc(sizeof(char *) * string_length, 
"model_output_filename");
+
     tmp_ptr = strcpy(input_filename, av[1]);
     tmp_ptr = strcpy(temp_filename, input_filename);
     tmp_ptr = strcat(temp_filename, ".tmp");
@@ -2116,10 +2121,18 @@
            &x_cell_size,
            &y_cell_size,
            &unit_elevation) == BRLCAD_ERROR) {
+           bu_free(input_filename, "input_filename");
+           bu_free(temp_filename, "temp_filename");
+           bu_free(dsp_output_filename, "dsp_output_filename");
+           bu_free(model_output_filename, "model_output_filename");
         bu_exit(BRLCAD_ERROR, "Error occured within function 'read_dem'. 
Import can not continue.\n");
     }
 
     if (convert_load_order(temp_filename, dsp_output_filename, &xdim, &ydim) 
== BRLCAD_ERROR) {
+           bu_free(input_filename, "input_filename");
+           bu_free(temp_filename, "temp_filename");
+           bu_free(dsp_output_filename, "dsp_output_filename");
+           bu_free(model_output_filename, "model_output_filename");
         bu_exit(BRLCAD_ERROR, "Error occured within function 
'convert_load_order'. Import can not continue.\n");
     }
 
@@ -2132,9 +2145,16 @@
            &x_cell_size,
            &y_cell_size,
            &unit_elevation) == BRLCAD_ERROR) {
+           bu_free(input_filename, "input_filename");
+           bu_free(temp_filename, "temp_filename");
+           bu_free(dsp_output_filename, "dsp_output_filename");
+           bu_free(model_output_filename, "model_output_filename");
         bu_exit(BRLCAD_ERROR, "Error occured within function 'create_model'. 
Model creation can not continue.\n");
     }
-
+    bu_free(input_filename, "input_filename");
+    bu_free(temp_filename, "temp_filename");
+    bu_free(dsp_output_filename, "dsp_output_filename");
+    bu_free(model_output_filename, "model_output_filename");
     return 0;
 }
 


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

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to