]> granicus.if.org Git - postgis/commitdiff
Fixed sprintf() calls to avoid overlapping memory,
authorSandro Santilli <strk@keybit.net>
Mon, 29 Aug 2005 11:48:33 +0000 (11:48 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 29 Aug 2005 11:48:33 +0000 (11:48 +0000)
reworked not-null objects existance check to reduce startup costs.

git-svn-id: http://svn.osgeo.org/postgis/trunk@1872 b70326c6-7e19-0410-871a-916f4a2858ee

CHANGES
loader/shp2pgsql.c

diff --git a/CHANGES b/CHANGES
index 85264b6d053d85218aa6294a0aa50505243975e4..d30ec64214b9a58411d85d3075f4695be7583b4a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,7 @@ PostGIS 1.0.4
        - Segfault fix in transform() handling of proj4 errors
        - Fixed some proj4 texts in spatial_ref_sys (missing +proj)
        - GiST indexing cleanup
+        - Loader: fixed string functions usage, reworked NULL objects check
 
 PostGIS 1.0.3
 2005/08/08
index 68e0f2b1f7d75e12a98d93992add726200ca836d..1c09178b4e80310b60e96fd5a2515424e61a5f27 100644 (file)
@@ -435,6 +435,7 @@ void
 OpenShape(void)
 {
        int j;
+       SHPObject *obj=NULL;
 
        hSHPHandle = SHPOpen( shp_file, "rb" );
        if (hSHPHandle == NULL) {
@@ -450,9 +451,17 @@ OpenShape(void)
        SHPGetInfo(hSHPHandle, &num_entities, &shpfiletype, NULL, NULL);
 
        /* Check we have at least a not-null geometry */
-       j=num_entities;
-       while( ( obj == NULL || obj->nVertices == 0 ) && j--)
+       for (j=0; j<num_entities; j++)
+       {
                obj = SHPReadObject(hSHPHandle,j);
+               if ( obj && obj->nVertices > 0 ) {
+                       SHPDestroyObject(obj);
+                       break;
+               }
+               SHPDestroyObject(obj);
+               obj=NULL;
+       }
+
        if ( obj == NULL) 
        {
                fprintf(stderr, "Shapefile contains %d NULL object(s)\n",
@@ -1415,11 +1424,12 @@ dump_ring(Ring *ring)
 {
        char *buf = malloc(256*ring->n);
        int i;
+
+       buf[0] = '\0';
        for (i=0; i<ring->n; i++)
        {
-               if (i) sprintf(buf, "%s,", buf);
-               sprintf(buf, "%s%g %g",
-                       buf,
+               if (i) strcat(buf, ",");
+               sprintf(buf+strlen(buf), "%g %g",
                        ring->list[i].x,
                        ring->list[i].y);
        }
@@ -1591,7 +1601,7 @@ GetFieldsSpec(void)
                for(z=0; z < j ; z++){
                        if(strcmp(field_names[z],name)==0){
                                strcat(name,"__");
-                               sprintf(name,"%s%i",name,j);
+                               sprintf(name+strlen(name),"%i",j);
                                break;
                        }
                }       
@@ -1599,9 +1609,14 @@ GetFieldsSpec(void)
                field_names[j] = malloc (strlen(name)+1);
                strcpy(field_names[j], name);
 
-               sprintf(col_names, "%s\"%s\",", col_names, name);
+               /*sprintf(col_names, "%s\"%s\",", col_names, name);*/
+               strcat(col_names, "\"");
+               strcat(col_names, name);
+               strcat(col_names, "\",");
        }
-       sprintf(col_names, "%s\"%s\")", col_names, geom);
+       /*sprintf(col_names, "%s\"%s\")", col_names, geom);*/
+       strcat(col_names, geom);
+       strcat(col_names, ")");
 }
 
 #ifdef USE_ICONV
@@ -1650,6 +1665,10 @@ utf8 (const char *fromcode, char *inputbuf)
 
 /**********************************************************************
  * $Log$
+ * Revision 1.95  2005/08/29 11:48:33  strk
+ * Fixed sprintf() calls to avoid overlapping memory,
+ * reworked not-null objects existance check to reduce startup costs.
+ *
  * Revision 1.94  2005/07/27 02:47:14  strk
  * Support for multibyte field names in loader
  *