diff --git a/lib/cunit/cu_pc_schema.c b/lib/cunit/cu_pc_schema.c index eda073b..3c0c30f 100644 --- a/lib/cunit/cu_pc_schema.c +++ b/lib/cunit/cu_pc_schema.c @@ -53,6 +53,20 @@ test_schema_from_xml() pc_schema_free(myschema); } +static void +test_schema_from_xml_with_empty_field() +{ + PCSCHEMA *myschema = NULL; + char *myxmlfile = "data/simple-schema-empty-field.xml"; + char *xmlstr = file_to_str(myxmlfile); + int rv = pc_schema_from_xml(xmlstr, &myschema); + + CU_ASSERT(rv == PC_SUCCESS); + + pc_schema_free(myschema); + pcfree(xmlstr); +} + static void test_schema_size() { @@ -204,6 +218,7 @@ test_schema_clone(void) CU_TestInfo schema_tests[] = { PC_TEST(test_schema_from_xml), + PC_TEST(test_schema_from_xml_with_empty_field), PC_TEST(test_schema_size), PC_TEST(test_dimension_get), PC_TEST(test_dimension_byteoffsets), diff --git a/lib/cunit/data/simple-schema-empty-field.xml b/lib/cunit/data/simple-schema-empty-field.xml new file mode 100644 index 0000000..72916d6 --- /dev/null +++ b/lib/cunit/data/simple-schema-empty-field.xml @@ -0,0 +1,45 @@ + + + + 1 + 4 + + X + int32_t + 0.01 + + + 2 + 4 + Y coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. + Y + int32_t + 0.01 + + + 3 + 4 + Z coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. + Z + int32_t + 0.01 + + + 4 + 2 + The intensity value is the integer representation of the pulse return magnitude. This value is optional and system specific. However, it should always be included if available. + Intensity + uint16_t + 1 + + + dimensional + + + + + + + 4326 + + diff --git a/lib/pc_schema.c b/lib/pc_schema.c index 8251cb0..0e0551b 100644 --- a/lib/pc_schema.c +++ b/lib/pc_schema.c @@ -458,7 +458,7 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema) /* These are the values of the dimension */ for ( child = cur->children; child; child = child->next ) { - if( child->type == XML_ELEMENT_NODE ) + if( child->type == XML_ELEMENT_NODE && child->children != NULL) { char *content = (char*)(child->children->content); char *name = (char*)(child->name);