fix UPER decoding of large [bit-]strings of size a multiple of 16K
diff --git a/skeletons/per_opentype.c b/skeletons/per_opentype.c
index afcc42c..70a1b44 100644
--- a/skeletons/per_opentype.c
+++ b/skeletons/per_opentype.c
@@ -27,33 +27,38 @@
  */
 int
 uper_open_type_put(asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
-	void *buf;
-	void *bptr;
-	ssize_t size;
-	size_t toGo;
+    void *buf;
+    void *bptr;
+    ssize_t size;
 
-	ASN_DEBUG("Open type put %s ...", td->name);
+    ASN_DEBUG("Open type put %s ...", td->name);
 
-	size = uper_encode_to_new_buffer(td, constraints, sptr, &buf);
-	if(size <= 0) return -1;
+    size = uper_encode_to_new_buffer(td, constraints, sptr, &buf);
+    if(size <= 0) return -1;
 
-	for(bptr = buf, toGo = size; toGo;) {
-		ssize_t maySave = uper_put_length(po, toGo);
-		ASN_DEBUG("Prepending length %d to %s and allowing to save %d",
-			(int)size, td->name, (int)maySave);
-		if(maySave < 0) break;
-		if(per_put_many_bits(po, bptr, maySave * 8)) break;
-		bptr = (char *)bptr + maySave;
-		toGo -= maySave;
-	}
+    ASN_DEBUG("Open type put %s of length %zd + overhead (1byte?)", td->name,
+              size);
 
-	FREEMEM(buf);
-	if(toGo) return -1;
+    bptr = buf;
+    do {
+        int need_eom = 0;
+        ssize_t maySave = uper_put_length(po, size, &need_eom);
+        ASN_DEBUG("Prepending length %zd to %s and allowing to save %d", size,
+                  td->name, (int)maySave);
+        if(maySave < 0) break;
+        if(per_put_many_bits(po, bptr, maySave * 8)) break;
+        bptr = (char *)bptr + maySave;
+        size -= maySave;
+        if(need_eom && uper_put_length(po, 0, 0)) {
+            FREEMEM(buf);
+            return -1;
+        }
+    } while(size);
 
-	ASN_DEBUG("Open type put %s of length %ld + overhead (1byte?)",
-		td->name, (long)size);
+    FREEMEM(buf);
+    if(size) return -1;
 
-	return 0;
+    return 0;
 }
 
 static asn_dec_rval_t