+
+ assert((n > 0U) /* && (n <= 32U)*/);
+#ifdef OPJ_UBSAN_BUILD
+ /* This assert fails for some corrupted images which are gracefully rejected */
+ /* Add this assert only for ubsan build. */
+ /* This is the condition for overflow not to occur below which is needed because of OPJ_NOSANITIZE */
+ assert(n <= 32U);
+#endif
+ v = 0U;
+ for (i = (OPJ_INT32)n - 1; i >= 0; i--) {
+ v |= opj_bio_getbit(bio) <<
+ i; /* can't overflow, opj_bio_getbit returns 0 or 1 */
+ }
+ return v;