[GRASS-SVN] r58721 - grass/branches/releasebranch_6_4/vector/v.in.dxf

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 13 23:45:31 PST 2014


Author: hcho
Date: 2014-01-13 23:45:31 -0800 (Mon, 13 Jan 2014)
New Revision: 58721

Modified:
   grass/branches/releasebranch_6_4/vector/v.in.dxf/dxf_to_vect.c
   grass/branches/releasebranch_6_4/vector/v.in.dxf/global.h
   grass/branches/releasebranch_6_4/vector/v.in.dxf/main.c
   grass/branches/releasebranch_6_4/vector/v.in.dxf/write_vect.c
Log:
Fixed possible infinite loop (Ticket 1914)

Modified: grass/branches/releasebranch_6_4/vector/v.in.dxf/dxf_to_vect.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.in.dxf/dxf_to_vect.c	2014-01-14 07:45:21 UTC (rev 58720)
+++ grass/branches/releasebranch_6_4/vector/v.in.dxf/dxf_to_vect.c	2014-01-14 07:45:31 UTC (rev 58721)
@@ -9,9 +9,11 @@
 #endif
 
 static void make_head(struct Map_info *);
+static int find_next_header_variable(struct dxf_file *);
 
 static BOUND_BOX ext, dxf_ext;
 
+/* returns 1 on success, otherwise 0 */
 int dxf_to_vect(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
@@ -22,18 +24,20 @@
 	code = dxf_get_code(dxf);
 	while (code != 0) {
 	    if (code == -2)	/* EOF */
-		return -1;
+		return 0;
 
 	    /* only looking for header groups (code == 9) */
-	    if (code != 9)
+	    if (code != 9) {
+		code = find_next_header_variable(dxf);
 		continue;
+	    }
 
 	    if (strcmp(dxf_buf, "$EXTMAX") == 0) {
 		/* read in lines and process information until a 9
 		 * or a 0 is read in */
 		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
 		    if (code == -2)	/* EOF */
-			return -1;
+			return 0;
 
 		    switch (code) {
 		    case 10:
@@ -58,7 +62,7 @@
 		 * or a 0 is read in */
 		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
 		    if (code == -2)	/* EOF */
-			return -1;
+			return 0;
 
 		    switch (code) {
 		    case 10:
@@ -77,12 +81,8 @@
 		    }
 		}
 	    }
-	    else {
-		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
-		    if (code == -2)	/* EOF */
-			return -1;
-		}
-	    }
+	    else
+		code = find_next_header_variable(dxf);
 
 	    if (bounds == 6)
 		break;
@@ -141,16 +141,32 @@
     G_free(ypnts);
     G_free(zpnts);
 
-    if (!flag_list) {
-	Vect_destroy_line_struct(Points);
-	write_done(Map);
-	if (found_layers)
-	    make_head(Map);
+    if (flag_list)
+	return 1;
+
+    Vect_destroy_line_struct(Points);
+
+    if (write_done(Map)) {
+	make_head(Map);
+	return 1;
     }
 
     return 0;
 }
 
+int find_next_header_variable(struct dxf_file *dxf)
+{
+    int code;
+
+    /* code  9: header variable
+     * code  0: ENDSEC
+     * code -2: EOF
+     */
+    while ((code = dxf_get_code(dxf)) != 9 && code != 0 && code != -2) ;
+
+    return code;
+}
+
 int check_ext(double x, double y, double z)
 {
     if (x < ext.W)

Modified: grass/branches/releasebranch_6_4/vector/v.in.dxf/global.h
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.in.dxf/global.h	2014-01-14 07:45:21 UTC (rev 58720)
+++ grass/branches/releasebranch_6_4/vector/v.in.dxf/global.h	2014-01-14 07:45:31 UTC (rev 58721)
@@ -27,7 +27,7 @@
 
 GLOBAL int flag_list, flag_extent, flag_table, flag_topo, flag_invert,
     flag_one_layer, flag_frame;
-GLOBAL int num_layers, found_layers;
+GLOBAL int num_layers;
 GLOBAL char **layers;
 GLOBAL char dxf_buf[DXF_BUF_SIZE], entity[DXF_BUF_SIZE];
 GLOBAL int ARR_MAX;
@@ -86,6 +86,6 @@
 #define write_face(a, b, c) write_vect(a, b, entity, "", c, GV_FACE)
 #define write_text(a, b, c) write_vect(a, b, entity, c, 1, GV_POINT)
 void write_vect(struct Map_info *, char *, char *, char *, int, int);
-void write_done(struct Map_info *);
+int write_done(struct Map_info *);
 
 #endif

Modified: grass/branches/releasebranch_6_4/vector/v.in.dxf/main.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.in.dxf/main.c	2014-01-14 07:45:21 UTC (rev 58720)
+++ grass/branches/releasebranch_6_4/vector/v.in.dxf/main.c	2014-01-14 07:45:31 UTC (rev 58721)
@@ -35,6 +35,7 @@
     struct dxf_file *dxf;
     struct Map_info *Map;
     char *output = NULL;
+    int ret;
 
     struct GModule *module;
     struct
@@ -173,7 +174,7 @@
     }
 
     /* import */
-    dxf_to_vect(dxf, Map);
+    ret = dxf_to_vect(dxf, Map);
 
     dxf_close(dxf);
 
@@ -182,7 +183,7 @@
     else {
 	Vect_close(Map);
 
-	if (found_layers) {
+	if (ret) {
 	    if (Vect_open_old(Map, output, G_mapset())) {
 		if (!flag_topo)
 		    if (!Vect_build(Map))

Modified: grass/branches/releasebranch_6_4/vector/v.in.dxf/write_vect.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.in.dxf/write_vect.c	2014-01-14 07:45:21 UTC (rev 58720)
+++ grass/branches/releasebranch_6_4/vector/v.in.dxf/write_vect.c	2014-01-14 07:45:31 UTC (rev 58721)
@@ -70,13 +70,13 @@
     return;
 }
 
-void write_done(struct Map_info *Map)
+int write_done(struct Map_info *Map)
 {
     int i;
 
-    if (!(found_layers = (num_fields > 0))) {
+    if (!num_fields) {
 	G_warning(_("No DXF layers found!"));
-	return;
+	return 0;
     }
 
     if (!flag_table) {
@@ -115,7 +115,7 @@
 	driver = NULL;
     }
 
-    return;
+    return 1;
 }
 
 static int get_field_cat(struct Map_info *Map, char *layer, int *field,



More information about the grass-commit mailing list