Hi

Thanks for reporting this.

There was more than one problem.  Although, since the number that is
read is not used, most of the fixes will not be noticeable.

The visible problems that are fixed are:

1. Any house or phone number that began with ':' and had an even
number of characters overall would crash.

2. Any house or phone number that contained a ':' would have it
converted to '-'.

Patch attached and a pre-compiled jar is at http://files.mkgmap.org.uk/download/230/mkgmap.jar

..Steve

I'm getting an assertion error compiling two of my maps (Colombia and
Venezuela) with mkgmap r3350
Number of MapFailedExceptions: 0
Exception in thread "main" java.lang.AssertionError: Invalid label
offset found 16091027
         at



Index: src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java	(revision 3351)
+++ src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java	(revision )
@@ -386,14 +386,13 @@
 
 			if (hasStreetNum) {
 				byte b = reader.get();
-				String num = reader.getBase11str(b, '-');
-				if (num.isEmpty()) {
+				if ((b & 0x80) == 0) {
 					int mpoffset = (b << 16) & 0xff0000;
 					mpoffset |= reader.getChar() & 0xffff;
 
-					poi.setComplexPhoneNumber(fetchLabel(mpoffset));
+					poi.setComplexStreetNumber(fetchLabel(mpoffset));
 				} else {
-					poi.setSimpleStreetNumber(num);
+					poi.setSimpleStreetNumber(reader.getBase11str(b, '-'));
 				}
 			}
 
@@ -425,16 +424,14 @@
 			
 			if (hasPhone) {
 				byte b = reader.get();
-				String num = reader.getBase11str(b, '-');
-				if (num.isEmpty()) {
+				if ((b & 0x80) == 0) {
 					// Yes this is a bit strange it is a byte followed by a char
 					int mpoffset = (b << 16) & 0xff0000;
 					mpoffset |= reader.getChar() & 0xffff;
 
-					Label label = fetchLabel(mpoffset);
-					poi.setComplexPhoneNumber(label);
+					poi.setComplexPhoneNumber(fetchLabel(mpoffset));
 				} else {
-					poi.setSimplePhoneNumber(num);
+					poi.setSimplePhoneNumber(reader.getBase11str(b, '-'));
 				}
 			}
 
Index: src/uk/me/parabola/imgfmt/app/BufferedImgFileReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/BufferedImgFileReader.java	(revision 3351)
+++ src/uk/me/parabola/imgfmt/app/BufferedImgFileReader.java	(revision )
@@ -201,11 +201,7 @@
 
 		int ch = firstChar & 0xff;
 		do {
-			if (str11.length() == 0) {
-				// Not found
-				if (ch < 0x80)
-					return "";
-			}
+			assert !(str11.length() == 0 && (ch & 0x80) == 0);
 
 			if ((ch & 0x80) != 0)
 				--term;
@@ -215,9 +211,8 @@
 		} while (term != 0);
 
 		// Remove any trailing delimiters
-		int idx;
-		if ((idx = str11.lastIndexOf("A")) >= 0)
-			str11.setLength(idx);
+		while (str11.length() > 0 && str11.charAt(str11.length()-1) == 'A')
+			str11.setLength(str11.length()-1);
 
 		// Convert in-line delimiters to the char delimiter
 		int len = str11.length();
Index: src/uk/me/parabola/imgfmt/app/lbl/POIRecord.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/POIRecord.java	(revision 3351)
+++ src/uk/me/parabola/imgfmt/app/lbl/POIRecord.java	(revision )
@@ -330,7 +330,7 @@
 		 * Encode a string as base 11.
 		 * @param str The input string.
 		 * @return If the string is not all numeric (or A) then false is returned
-		 * and the string will be encoded as a label instead.
+		 * and this object is invalid.
 		 */
 		public boolean set(String str) {
 
@@ -393,10 +393,18 @@
 			return encodedSize;
 		}
 
-		private int decodeChar(char ch)
-		{
+		/**
+		 * Convert the characters '0' to '9' and '-' to a number 0-10 (base 11).
+		 * @param ch The character to convert.
+		 * @return A number between 0 and 10 or -1 if the character is not valid.
+		 */
+		private int decodeChar(char ch) {
+			if (ch == '-')
+				return 10;
+			else if (ch >= '0' && ch <= '9')
-			return (ch - '0');
+				return (ch - '0');
+			else
+				return -1;
 		}
-
 	}	
 }
Index: src/uk/me/parabola/mkgmap/build/MapBuilder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/build/MapBuilder.java	(revision 3351)
+++ src/uk/me/parabola/mkgmap/build/MapBuilder.java	(revision )
@@ -524,22 +524,16 @@
 					r.setStreetName(streetName);			  
 				}
 
-				if(p.getHouseNumber() != null)
-				{
-					if(!r.setSimpleStreetNumber(p.getHouseNumber()))
-					{
-						Label streetNumber = lbl.newLabel(p.getHouseNumber());
-						r.setComplexStreetNumber(streetNumber);
+				String houseNumber = p.getHouseNumber();
+				if (houseNumber != null && !houseNumber.isEmpty()) {
+					if(!r.setSimpleStreetNumber(houseNumber))
+						r.setComplexStreetNumber(lbl.newLabel(houseNumber));
-					}
+				}
-				}
 
-				if(p.getPhone() != null)
-				{
-					if(!r.setSimplePhoneNumber(p.getPhone()))
-					{
-						Label phoneNumber = lbl.newLabel(p.getPhone());
-						r.setComplexPhoneNumber(phoneNumber);
-					}
+				String phone = p.getPhone();
+				if (phone != null && !phone.isEmpty()) {
+					if(!r.setSimplePhoneNumber(phone))
+						r.setComplexPhoneNumber(lbl.newLabel(phone));
 				}	
 		  	
 				poimap.put(p, r);
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to