From: Sandro Santilli Date: Mon, 29 Aug 2005 11:48:33 +0000 (+0000) Subject: Fixed sprintf() calls to avoid overlapping memory, X-Git-Tag: pgis_1_1_0~281 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cdd5e76ce34716f97a36a37785a38a5abdb00a8;p=postgis Fixed sprintf() calls to avoid overlapping memory, 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 --- diff --git a/CHANGES b/CHANGES index 85264b6d0..d30ec6421 100644 --- 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 diff --git a/loader/shp2pgsql.c b/loader/shp2pgsql.c index 68e0f2b1f..1c09178b4 100644 --- a/loader/shp2pgsql.c +++ b/loader/shp2pgsql.c @@ -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; jnVertices > 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; in; 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 *