diff --git a/lib/cunit/cu_pc_schema.c b/lib/cunit/cu_pc_schema.c index ecb7f06..eda073b 100644 --- a/lib/cunit/cu_pc_schema.c +++ b/lib/cunit/cu_pc_schema.c @@ -147,8 +147,10 @@ static void test_schema_clone(void) { int i; + PCSCHEMA *myschema; PCSCHEMA *clone = pc_schema_clone(schema); hashtable *hash, *chash; + char *xmlstr; CU_ASSERT_EQUAL(clone->pcid, schema->pcid); CU_ASSERT_EQUAL(clone->ndims, schema->ndims); CU_ASSERT_EQUAL(clone->size, schema->size); @@ -185,6 +187,17 @@ test_schema_clone(void) } pc_schema_free(clone); + + /* See https://github.com/pgpointcloud/pointcloud/issues/66 */ + xmlstr = "1"; + i = pc_schema_from_xml(xmlstr, &myschema); + CU_ASSERT_EQUAL(i, PC_SUCCESS); + clone = pc_schema_clone(myschema); + CU_ASSERT_EQUAL(clone->ndims, myschema->ndims); + CU_ASSERT_EQUAL(clone->dims[0]->name, NULL); + CU_ASSERT_EQUAL(clone->dims[0]->description, NULL); + pc_schema_free(myschema); + pc_schema_free(clone); } /* REGISTER ***********************************************************/ diff --git a/lib/pc_schema.c b/lib/pc_schema.c index 0acddbd..b800c17 100644 --- a/lib/pc_schema.c +++ b/lib/pc_schema.c @@ -164,8 +164,8 @@ pc_dimension_clone(const PCDIMENSION *dim) /* Copy all the inline data */ memcpy(pcd, dim, sizeof(PCDIMENSION)); /* Copy the referenced data */ - pcd->name = pcstrdup(dim->name); - pcd->description = pcstrdup(dim->description); + if ( dim->name ) pcd->name = pcstrdup(dim->name); + if ( dim->description ) pcd->description = pcstrdup(dim->description); return pcd; }