[GRASS-SVN] r55641 - grass/trunk/vector/v.in.dxf

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 6 02:54:31 PDT 2013


Author: hcho
Date: 2013-04-06 02:54:31 -0700 (Sat, 06 Apr 2013)
New Revision: 55641

Modified:
   grass/trunk/vector/v.in.dxf/dxf_to_vect.c
Log:
Fixed a possible infinite loop

Modified: grass/trunk/vector/v.in.dxf/dxf_to_vect.c
===================================================================
--- grass/trunk/vector/v.in.dxf/dxf_to_vect.c	2013-04-05 19:50:34 UTC (rev 55640)
+++ grass/trunk/vector/v.in.dxf/dxf_to_vect.c	2013-04-06 09:54:31 UTC (rev 55641)
@@ -16,18 +16,21 @@
 int dxf_to_vect(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
+
     int bounds = 0;
 
     if (dxf_find_header(dxf)) {
 	/* code == 0: end of the header section */
 	code = dxf_get_code(dxf);
-	while (code != 0) {
+	while (code != 0) {	/* ENDSEC */
 	    if (code == -2)	/* EOF */
 		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
@@ -78,12 +81,8 @@
 		    }
 		}
 	    }
-	    else {
-		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
-		    if (code == -2)	/* EOF */
-			return 0;
-		}
-	    }
+	    else
+		code = find_next_header_variable(dxf);
 
 	    if (bounds == 6)
 		break;
@@ -153,6 +152,19 @@
     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)



More information about the grass-commit mailing list