[GRASS-SVN] r32202 - in grass/trunk: include lib/ogsf

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 22 05:33:00 EDT 2008


Author: martinl
Date: 2008-07-22 05:32:59 -0400 (Tue, 22 Jul 2008)
New Revision: 32202

Modified:
   grass/trunk/include/gstypes.h
   grass/trunk/lib/ogsf/GP2.c
   grass/trunk/lib/ogsf/GV2.c
   grass/trunk/lib/ogsf/gp.c
   grass/trunk/lib/ogsf/gsds.c
   grass/trunk/lib/ogsf/gv.c
   grass/trunk/lib/ogsf/gvl_file.c
Log:
ogsflib: avoid using statically allocated buffer for filenames (NAME_SIZ)


Modified: grass/trunk/include/gstypes.h
===================================================================
--- grass/trunk/include/gstypes.h	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/include/gstypes.h	2008-07-22 09:32:59 UTC (rev 32202)
@@ -66,7 +66,6 @@
 #define CF_USR_CHANGED 0x000010
 #define CF_CHARSCALED  0x000100
 
-#define NAME_SIZ 80
 #define MAX_TF 6
 
 #define MASK_TL 0x10000000
@@ -113,7 +112,7 @@
     int dims[MAXDIMS];
     int ndims;
     int numbytes;
-    char unique_name[NAME_SIZ];
+    char *unique_name;
     typbuff databuff;
     IFLAG changed;
     int need_reload;
@@ -173,7 +172,7 @@
     int flat_val;
     int n_surfs;
     int color, width;
-    char filename[NAME_SIZ];
+    char *filename;
     float x_trans, y_trans, z_trans;
 /* also maybe center & rotate? */
     geoline *lines;
@@ -224,7 +223,7 @@
 /* ACS_MODIFY OneLine site_attr ************************************************/
     int use_attr[GPT_MAX_ATTR]; /* ST_ATT_COLOR, ST_ATT_MARKER, ST_ATT_SIZE, ST_ATT_NONE, for multiple attr's */
 
-    char filename[NAME_SIZ];
+    char *filename;
     transform attr_trans;
     float size;
     float x_trans, y_trans, z_trans;
@@ -239,7 +238,7 @@
     int data_id; /* id */
     IFLAG file_type; /* file type */
     unsigned int count; /* number of referencies to this file */
-    char file_name[NAME_SIZ]; /* file name */
+    char *file_name; /* file name */
 
     IFLAG data_type;
     void *map; /* pointer to volume file descriptor */

Modified: grass/trunk/lib/ogsf/GP2.c
===================================================================
--- grass/trunk/lib/ogsf/GP2.c	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/lib/ogsf/GP2.c	2008-07-22 09:32:59 UTC (rev 32202)
@@ -182,9 +182,7 @@
 	gp_free_sitemem(gp);
     }
 
-    if (NAME_SIZ > strlen(filename)) {
-	strcpy(gp->filename, filename);
-    }
+    gp->filename = G_store(filename);
 
     gp->points = Gp_load_sites(filename, &(gp->n_sites),
 			       &(gp->has_z), &(gp->has_att));
@@ -199,6 +197,8 @@
 /*!
   \brief Get point set filename
 
+  Note: char array is allocated by G_store()
+
   \param id point set id
   \param[out] filename point set filename
 
@@ -213,7 +213,7 @@
 	return (-1);
     }
 
-    strcpy(filename, gp->filename);
+    filename = G_store(gp->filename);
 
     return (1);
 }

Modified: grass/trunk/lib/ogsf/GV2.c
===================================================================
--- grass/trunk/lib/ogsf/GV2.c	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/lib/ogsf/GV2.c	2008-07-22 09:32:59 UTC (rev 32202)
@@ -183,9 +183,7 @@
 	gv_free_vectmem(gv);
     }
 
-    if (NAME_SIZ > strlen(filename)) {
-	strcpy(gv->filename, filename);
-    }
+    gv->filename = G_store(filename);
 
     if ((gv->lines = Gv_load_vect(filename, &(gv->n_lines)))) {
 	return (1);
@@ -197,6 +195,8 @@
 /*!
   \brief Get vector map name
 
+  Note: char array is allocated by G_store()
+
   \param id vector set id
   \param filename filename
 
@@ -211,7 +211,7 @@
 	return (-1);
     }
 
-    strcpy(filename, gv->filename);
+    filename = G_store(gv->filename);
 
     return (1);
 }

Modified: grass/trunk/lib/ogsf/gp.c
===================================================================
--- grass/trunk/lib/ogsf/gp.c	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/lib/ogsf/gp.c	2008-07-22 09:32:59 UTC (rev 32202)
@@ -193,6 +193,7 @@
 
     GS_get_longdim(&dim);
 
+    gp->filename = NULL;
     gp->n_sites = gp->use_z = gp->n_surfs = gp->use_mem = 0;
     gp->x_trans = gp->y_trans = gp->z_trans = 0.0;
     gp->size = dim / 100.;
@@ -338,6 +339,8 @@
 {
     geopoint *gpt, *tmp;
 
+    G_free((void *) fp->filename);
+    fp->filename = NULL;
     if (fp->points) {
 	for (gpt = fp->points; gpt;) {
 	    if (gpt->cattr) {

Modified: grass/trunk/lib/ogsf/gsds.c
===================================================================
--- grass/trunk/lib/ogsf/gsds.c	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/lib/ogsf/gsds.c	2008-07-22 09:32:59 UTC (rev 32202)
@@ -247,7 +247,7 @@
 	    new->dims[i] = 0;
 	}
 
-	strcpy(new->unique_name, name);
+	new->unique_name = G_store(name);
 	new->databuff.fb = NULL;
 	new->databuff.ib = NULL;
 	new->databuff.sb = NULL;
@@ -304,7 +304,7 @@
 {
     int i;
     dataset *fds;
-    static char retstr[160];
+    static char retstr[GPATH_MAX];
 
     for (i = 0; i < Numsets; i++) {
 	if (Data[i]->data_id == id) {
@@ -319,7 +319,7 @@
 }
 
 /*!
-  \brief ADD
+  \brief Free allocated dataset
 
   \param id
 
@@ -338,7 +338,8 @@
 	    found = 1;
 	    fds = Data[i];
 	    free_data_buffs(fds, ATTY_ANY);
-	    strcpy(fds->unique_name, "");
+	    G_free((void *)fds->unique_name);
+	    fds->unique_name = NULL;
 	    fds->data_id = 0;
 
 	    for (j = i; j < (Numsets - 1); j++) {

Modified: grass/trunk/lib/ogsf/gv.c
===================================================================
--- grass/trunk/lib/ogsf/gv.c	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/lib/ogsf/gv.c	2008-07-22 09:32:59 UTC (rev 32202)
@@ -187,6 +187,7 @@
 	return (-1);
     }
 
+    gv->filename = NULL;
     gv->n_lines = gv->n_surfs = gv->use_mem = 0;
     gv->x_trans = gv->y_trans = gv->z_trans = 0.0;
     gv->lines = NULL;
@@ -301,6 +302,9 @@
 {
     geoline *gln, *tmpln;
 
+    G_free((void *) fv->filename);
+    fv->filename = NULL;
+    
     if (fv->lines) {
 	for (gln = fv->lines; gln;) {
 	    if (gln->dims == 2) {

Modified: grass/trunk/lib/ogsf/gvl_file.c
===================================================================
--- grass/trunk/lib/ogsf/gvl_file.c	2008-07-22 06:40:29 UTC (rev 32201)
+++ grass/trunk/lib/ogsf/gvl_file.c	2008-07-22 09:32:59 UTC (rev 32202)
@@ -167,7 +167,7 @@
 {
     int i;
     geovol_file *fvf;
-    static char retstr[NAME_SIZ];
+    static char retstr[GPATH_MAX];
     
     for (i = 0; i < Numfiles; i++) {
 	if (Data[i]->data_id == id) {
@@ -312,7 +312,7 @@
 	Numfiles++;
 	new->data_id = Cur_id++;
 	
-	strcpy(new->file_name, name);
+	new->file_name = G_store(name);
 	new->file_type = file_type;
 	new->count = 1;
 	new->map = m;
@@ -378,7 +378,10 @@
 	    } else {
 		close_volfile(fvf->map, fvf->file_type);
 		free_volfile_buffs(fvf);
-		strcpy(fvf->file_name, "");
+
+		G_free(fvf->file_name);
+		fvf->file_name = NULL;
+
 		fvf->data_id = 0;
 		
 		for (j = i; j < (Numfiles - 1); j++) {



More information about the grass-commit mailing list