encode BIT STRING in a minimum number of bits for CANONICAL-UPER
diff --git a/skeletons/BIT_STRING_oer.c b/skeletons/BIT_STRING_oer.c
index e887228..b18e27f 100644
--- a/skeletons/BIT_STRING_oer.c
+++ b/skeletons/BIT_STRING_oer.c
@@ -47,6 +47,8 @@
         }
 
         if(expected_length < 1) {
+            ASN__DECODE_FAILED;
+        } else if(expected_length > size) {
             ASN__DECODE_STARVED;
         }