Fixed bug #309338, reported by Kupriyanov Anotolij. Added a regression

* xmlschemastypes.c: Fixed bug #309338, reported by Kupriyanov
  Anotolij.
* test/schemas/bug309338* result/schemas/bug309338*:
  Added a regression test for the above bug.
diff --git a/xmlschemastypes.c b/xmlschemastypes.c
index d9fee06..27f7b53 100644
--- a/xmlschemastypes.c
+++ b/xmlschemastypes.c
@@ -2194,7 +2194,8 @@
 		 	* If a mixed decimal, get rid of trailing zeroes
 		 	*/
 			if (dec != -1) {
-			    while ((cptr > cval) && (*(cptr-1) == '0')) {
+			    while ((len > dec) && (cptr > cval) &&

+				(*(cptr-1) == '0')) {
 				cptr--;
 				len--;
 			    }