bits BUGFIX one byte smaller bitmap

... for specific bit count.

Fixes #1848
diff --git a/src/plugins_types/bits.c b/src/plugins_types/bits.c
index 5d198e3..04adace 100644
--- a/src/plugins_types/bits.c
+++ b/src/plugins_types/bits.c
@@ -58,8 +58,8 @@
 
     LY_CHECK_ARG_RET(NULL, type, type->basetype == LY_TYPE_BITS, 0);
 
-    /* minimum needed bytes to hold all the bit positions */
-    needed_bytes = (BITS_LAST_BIT_POSITION(type) / 8) + (BITS_LAST_BIT_POSITION(type) % 8 ? 1 : 0);
+    /* minimum needed bytes to hold all the bit positions (which start at 0) */
+    needed_bytes = ((BITS_LAST_BIT_POSITION(type) + 1) / 8) + ((BITS_LAST_BIT_POSITION(type) + 1) % 8 ? 1 : 0);
     LY_CHECK_ERR_RET(!needed_bytes, LOGINT(NULL), 0);
 
     if ((needed_bytes == 1) || (needed_bytes == 2)) {
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 4416fc3..9d4edcd 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -2639,6 +2639,11 @@
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(UTEST_LYCTX, leaf->dflt, LY_VALUE_SCHEMA, NULL, &dynamic, NULL));
     assert_int_equal(0, dynamic);
 
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;"
+            "grouping alg {leaf alg2 {type bits {"
+            "bit ftp;bit h323-q931;bit h323-ras;bit pptp;bit rtsp;bit sip-tcp;bit sip-udp;bit tftp;bit dns-udp;}}}"
+            "container conf {uses alg {refine alg2 {default \"dns-udp\";}}}}", LYS_IN_YANG, &mod));
+
     /* invalid */
     assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
             "uses g:grp {refine c {default hello;}}}", LYS_IN_YANG, &mod));