OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { OPJ_INT32 i; OPJ_UINT32 v; v = 0; for (i = n - 1; i >= 0; i--) { v += opj_bio_getbit(bio) << i; } return v; }
uint32_t opj_bio_read(opj_bio_t *bio, uint32_t n) { uint32_t i; uint32_t v; 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 = n - 1; i < n; i--) { /* overflow used for end-loop condition */ v |= opj_bio_getbit(bio) << i; /* can't overflow, opj_bio_getbit returns 0 or 1 */ } return v; }