Roi Atalla avatar Roi Atalla committed 66d7b4a

Discovered that all the parse<Type> methods throw NumberFormatException if the number is out of range. This is problematic for unsigned values whose positive values may exceed the range. The fix is to just parse them all as Long's then cast down to their respective types. This preserves all data.

Comments (0)

Files changed (1)

src/com/ra4king/opengl/util/Mesh.java

 		UBYTE("ubyte", GL_UNSIGNED_BYTE, 1) {
 			public void store(ByteBuffer b, String[] data) {
 				for(String s : data)
-					b.put(Byte.parseByte(s));
+					b.put((byte)Long.parseLong(s));
 			}
 		},
 		USHORT("ushort", GL_UNSIGNED_SHORT, 2) {
 			public void store(ByteBuffer b, String[] data) {
 				for(String s : data)
-					b.putShort(Short.parseShort(s));
+					b.putShort((short)Long.parseLong(s));
 			}
 		},
 		UINT("uint", GL_UNSIGNED_INT, 4) {
 			public void store(ByteBuffer b, String[] data) {
 				for(String s : data)
-					b.putInt(Integer.parseInt(s));
+					b.putInt((int)Long.parseLong(s));
 			}
 		};
 		
 				case GL_INT:
 				case GL_UNSIGNED_INT:
 					for(String s : data)
-						b.putInt(Integer.parseInt(s));
+						b.putInt((int)Long.parseLong(s));
 					break;
 				case GL_SHORT:
 				case GL_UNSIGNED_SHORT:
 					for(String s : data)
-						b.putShort(Short.parseShort(s));
+						b.putShort((short)Long.parseLong(s));
 					break;
 				case GL_BYTE:
 				case GL_UNSIGNED_BYTE:
 					for(String s : data)
-						b.put(Byte.parseByte(s));
+						b.put((byte)Long.parseLong(s));
 					break;
 			}
 		}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.