]> granicus.if.org Git - postgis/commitdiff
initialize state->num_fields and state->pgfieldtypes so doesn't cause intermittent...
authorRegina Obe <lr@pcorp.us>
Mon, 11 Sep 2017 15:50:06 +0000 (15:50 +0000)
committerRegina Obe <lr@pcorp.us>
Mon, 11 Sep 2017 15:50:06 +0000 (15:50 +0000)
Closes #3839 for PostGIS 2.3.4

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

NEWS
loader/shp2pgsql-core.c

diff --git a/NEWS b/NEWS
index 11f5d647fe4784d04adf02a65fd3c1929fc11cb2..345eae7cb09891da4fa50fb5c4d8168574a8d449 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,8 @@ PostGIS 2.3.4
            and partitioned tables
   - #3806, Reverse geocoder missing suffix direction when present
   - #3698, loading census tabblock is broken
+  - #3839, loader tests sometimes crash because of variables not initialized
+            also reenable cunit loader tess to always run.
 
 
 PostGIS 2.3.3
index 8070179f53528c6fde14445e37000ba46dde4112..dcc5e0c4806cc8c0476c0de281b6e68f3e7daba2 100644 (file)
@@ -248,7 +248,7 @@ GeneratePointGeometry(SHPLOADERSTATE *state, SHPObject *obj, char **geometry, in
        {
                /* Create a ptarray containing a single point */
                POINTARRAY *pa = ptarray_construct_empty(state->has_z, state->has_m, 1);
-               
+
                /* Generate the point */
                point4d.x = obj->padfX[u];
                point4d.y = obj->padfY[u];
@@ -294,7 +294,7 @@ GeneratePointGeometry(SHPLOADERSTATE *state, SHPObject *obj, char **geometry, in
 
        /* Free all of the allocated items */
        lwgeom_free(lwgeom);
-       
+
        /* Return the string - everything ok */
        *geometry = mem;
 
@@ -639,7 +639,7 @@ GeneratePolygonGeometry(SHPLOADERSTATE *state, SHPObject *obj, char **geometry)
        for (pi = 0; pi < polygon_total; pi++)
        {
                LWPOLY *lwpoly = lwpoly_construct_empty(state->from_srid, state->has_z, state->has_m);
-               
+
                Ring *polyring;
                int ring_index = 0;
 
@@ -779,11 +779,13 @@ ShpLoaderCreate(SHPLOADERCONFIG *config)
        state->hDBFHandle = NULL;
        state->has_z = 0;
        state->has_m = 0;
+       state->num_fields = 0;
        state->types = NULL;
        state->widths = NULL;
        state->precisions = NULL;
        state->col_names = NULL;
        state->field_names = NULL;
+       state->pgfieldtypes = NULL;
 
        state->from_srid = config->shp_sr_id;
        state->to_srid = config->sr_id;
@@ -856,8 +858,8 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
 
                return SHPLOADERERR;
        }
-       
-               
+
+
        /* Open the column map if one was specified */
        if (state->config->column_map_filename)
        {
@@ -865,7 +867,7 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
                                  &state->column_map, state->message, SHPLOADERMSGLEN);
                if (!ret) return SHPLOADERERR;
        }
-       
+
        /* User hasn't altered the default encoding preference... */
        if ( strcmp(state->config->encoding, ENCODING_DEFAULT) == 0 )
        {
@@ -1023,7 +1025,7 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
 
                        break;
                }
-               
+
                /* Force Z/M-handling if configured to do so */
                switch(state->config->force_output)
                {
@@ -1121,7 +1123,7 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
                        strncpy(name, utf8str, MAXFIELDNAMELEN);
                        free(utf8str);
                }
-               
+
                /* If a column map file has been passed in, use this to create the postgresql field name from
                   the dbf column name */
                {
@@ -1192,7 +1194,7 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
                        if (state->config->forceint4 || (state->widths[j] >=5 && state->widths[j] < 10))
                        {
                                state->pgfieldtypes[j] = malloc(strlen("int4") + 1);
-                               strcpy(state->pgfieldtypes[j], "int4"); 
+                               strcpy(state->pgfieldtypes[j], "int4");
                        }
                        else if (state->widths[j] < 5)
                        {
@@ -1229,7 +1231,7 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
                        snprintf(state->message, SHPLOADERMSGLEN, _("Invalid type %x in DBF file"), state->types[j]);
                        return SHPLOADERERR;
                }
-               
+
                strcat(state->col_names, "\"");
                strcat(state->col_names, name);
 
@@ -1267,13 +1269,13 @@ ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
           for handling string resizing during append */
        sb = stringbuffer_create();
        stringbuffer_clear(sb);
-       
+
        /* Set the client encoding if required */
        if (state->config->encoding)
        {
                stringbuffer_aprintf(sb, "SET CLIENT_ENCODING TO UTF8;\n");
        }
-       
+
        /* Use SQL-standard string escaping rather than PostgreSQL standard */
        stringbuffer_aprintf(sb, "SET STANDARD_CONFORMING_STRINGS TO ON;\n");
 
@@ -1344,7 +1346,7 @@ ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
 
                        /* First output the raw field type string */
                        stringbuffer_aprintf(sb, "%s", state->pgfieldtypes[j]);
-                       
+
                        /* Some types do have typmods though... */
                        if (!strcmp("varchar", state->pgfieldtypes[j]))
                                stringbuffer_aprintf(sb, "(%d)", state->widths[j]);
@@ -1679,7 +1681,7 @@ ShpLoaderGenerateSQLRowStatement(SHPLOADERSTATE *state, int item, char **strreco
        {
                /* Force the locale to C */
                char *oldlocale = setlocale(LC_NUMERIC, "C");
-               
+
                /* Handle the case of a NULL shape */
                if (obj->nVertices == 0)
                {
@@ -1772,7 +1774,7 @@ ShpLoaderGenerateSQLRowStatement(SHPLOADERSTATE *state, int item, char **strreco
 
                /* Tidy up everything */
                SHPDestroyObject(obj);
-               
+
                setlocale(LC_NUMERIC, oldlocale);
        }
 
@@ -1866,7 +1868,7 @@ ShpLoaderDestroy(SHPLOADERSTATE *state)
 {
        /* Destroy a state object created with ShpLoaderOpenShape */
        int i;
-       
+
        if (state != NULL)
        {
                if (state->hSHPHandle)
@@ -1884,7 +1886,7 @@ ShpLoaderDestroy(SHPLOADERSTATE *state)
                {
                        for (i = 0; i < state->num_fields; i++)
                                free(state->pgfieldtypes[i]);
-                       
+
                        free(state->pgfieldtypes);
                }
                if (state->types)
@@ -1898,7 +1900,7 @@ ShpLoaderDestroy(SHPLOADERSTATE *state)
 
                /* Free any column map fieldnames if specified */
                colmap_clean(&state->column_map);
-               
+
                /* Free the state itself */
                free(state);
        }